Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Snake script by popinman322
- --]]
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local PlayerBackpack = LocalPlayer.Backpack
- local ToolName = "[ Snake ]"
- local HopperProps = {
- Name = ToolName;
- Parent = PlayerBackpack;
- }
- local function new(Class, Parent, Props)
- local Inst = Instance.new(Class, Parent)
- if Props["FormFactor"] then
- Inst["FormFactor"] = Props["FormFactor"]
- end
- for Prop, Val in pairs(Props) do
- Inst[Prop] = Val
- end
- return Inst
- end
- -- Snake creation and manipulation
- local NumLinks = 20
- local Step = CFrame.new(0,0,0.1)
- local Steps = {}
- local MaxSteps = NumLinks + 1
- local function RecordStep(Step)
- local Out = {}
- for i=1, #Steps do
- Out[i+1] = Steps[i]
- end
- Out[#Steps] = nil
- Out[1] = Step
- Steps = Out
- end
- local function GetStep(Index)
- if Steps[Index] == nil then
- return Steps[#Steps]
- end
- return Steps[Index]
- end
- local Snake = new("Model", LocalPlayer.Character,
- {
- Name = "Snake"
- });
- local Head = new("Seat", Snake,
- {
- Name = "Head";
- FormFactor = "Custom";
- BrickColor = BrickColor.Red;
- Reflectance = 0.7;
- Transparency = 0.25;
- Shape = Enum.PartType.Ball;
- Size = Vector3.new(5,5,5);
- Anchored = true;
- TopSurface = "Smooth";
- BottomSurface = "Smooth";
- });
- local Links = {}
- local function NewLink()
- return new("Part", Snake, {
- Name = "Link";
- BrickColor = BrickColor.Blue;
- Reflectance = 0.5;
- Transparency = 0.4;
- FormFactor = "Custom";
- Size = Vector3.new(3,3,3);
- Anchored = true;
- TopSurface = "Smooth";
- BottomSurface = "Smooth";
- })
- end
- for i=1, NumLinks do
- table.insert(Links, NewLink())
- end
- -- Mouse events
- local IsDown = false
- local function OnMouseMoved(Mouse)
- if IsDown then
- RecordStep(CFrame.new(Head.Position, Mouse.Hit.p) * Step)
- end
- Head.CFrame = GetStep(1)
- for i=2, NumLinks+1 do
- Links[i-1].CFrame = GetStep(i)
- end
- end
- local function OnMouseDown()
- IsDown = true
- end
- local function OnMouseUp()
- IsDown = false
- end
- local function KeyDown(Mouse, Key)
- end
- local function KeyUp(Mouse, Key)
- end
- -- Tool creation and management
- local Hop;
- if not script then -- We're being loadstring'd
- Hop = new("HopperBin", PlayerBackpack, HopperProps)
- end
- if not script.Parent:IsA("HopperBin") then
- Hop = new("HopperBin", PlayerBackpack, HopperProps)
- local Scr = script:Clone()
- Scr.Parent = Hop
- script:Destroy()
- else
- if not Hop then
- Hop = script.Parent
- end
- Hop.Selected:connect(function(Mouse)
- Mouse.Button1Down:connect(OnMouseDown)
- Mouse.Button1Up:connect(OnMouseUp)
- -- Mouse.Idle and Mouse.Move fire in a continuous loop
- Mouse.Move:connect(function()
- OnMouseMoved(Mouse)
- end)
- Mouse.Idle:connect(function()
- OnMouseMoved(Mouse)
- end)
- Mouse.KeyDown:connect(function(Key)
- KeyDown(Mouse, Key)
- end)
- Mouse.KeyUp:connect(function(Key)
- KeyUp(Mouse, Key)
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement