This script works, but is there anything preventing it from working in-game?
Player = game.Players.LocalPlayer Character = Player.Character Torso = Character.Torso Mouse = Player:GetMouse() RS = Character.Torso["Right Shoulder"] LS = Character.Torso["Left Shoulder"] hold = false f = script.Parent Mouse.KeyDown:connect(function(key) key = key:lower() if key == "v" then RS.C0 = RS.C0 * CFrame.Angles(0,.5,1) LS.C0 = LS.C0 * CFrame.Angles(0,-.5,-1) local x = Instance.new("Part", Character) x.CFrame = Torso.CFrame * CFrame.new(0,-5,-5) x.Shape = "Ball" x.BrickColor = BrickColor.new("Teal") x.Size = x.Size + Vector3.new(1,1,1) x.Anchored = true x.TopSurface = 0 x.BottomSurface = 0 x.Material = "Concrete" local s = Instance.new("ParticleEmitter", x) s.LightEmission = 100 s.Transparency = 0.2 s.Rate = 10 s.VelocitySpread = 100000 end end) Mouse.KeyUp:connect(function(key) key = key:lower() if key == "v" then hold = false end end) Mouse.KeyDown:connect(function(key) key = key:lower() if key == "p" then for i = 1, 4 do wait(0.00001) RS.C0 = RS.C0*CFrame.Angles(0,0,5) LS.C0 = LS.C0*CFrame.Angles(0,0,-5) end end end)
Why aren't my scripts running in the server
? Easy Answer, Because Some scripts will run before the player is even in the game, casting an error.
How do I stop this madness? Well you can use the WaitForChild
or repeat wait() until childName
.
WaitForChild
?WaitForChild
, yields the current thread, if a child with the given title, then returns the child, and Continues on. What if the Child didn't exist, then your code(code below WaitForChild) will not run at all.
Player = game.Players.LocalPlayer repeat wait() until Player.Character Character = Player.Character Torso = Character:WaitForChild("Torso") Mouse = Player:GetMouse() RS = Torso["Right Shoulder"] LS = Torso["Left Shoulder"] hold = false f = script.Parent Mouse.KeyDown:connect(function(key) key = key:lower() if key == "v" then RS.C0 = RS.C0 * CFrame.Angles(0,.5,1) LS.C0 = LS.C0 * CFrame.Angles(0,-.5,-1) local x = Instance.new("Part", Character) x.CFrame = Torso.CFrame * CFrame.new(0,-5,-5) x.Shape = "Ball" x.BrickColor = BrickColor.new("Teal") x.Size = x.Size + Vector3.new(1,1,1) x.Anchored = true x.TopSurface = 0 x.BottomSurface = 0 x.Material = "Concrete" local s = Instance.new("ParticleEmitter", x) s.LightEmission = 100 s.Transparency = 0.2 s.Rate = 10 s.VelocitySpread = 100000 end end) Mouse.KeyUp:connect(function(key) key = key:lower() if key == "v" then hold = false end end) Mouse.KeyDown:connect(function(key) key = key:lower() if key == "p" then for i = 1, 4 do wait(0.00001) RS.C0 = RS.C0*CFrame.Angles(0,0,5) LS.C0 = LS.C0*CFrame.Angles(0,0,-5) end end end)