What cause this?
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?
How do I stop this madness? Well you can use the WaitForChild
or repeat wait() until childName
.
What is 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.
01 | Player = game.Players.LocalPlayer |
03 | repeat wait() until Player.Character |
05 | Character = Player.Character |
06 | Torso = Character:WaitForChild( "Torso" ) |
07 | Mouse = Player:GetMouse() |
08 | RS = Torso [ "Right Shoulder" ] |
09 | LS = Torso [ "Left Shoulder" ] |
13 | Mouse.KeyDown:connect( function (key) |
16 | RS.C 0 = RS.C 0 * CFrame.Angles( 0 ,. 5 , 1 ) |
17 | LS.C 0 = LS.C 0 * CFrame.Angles( 0 ,-. 5 ,- 1 ) |
19 | local x = Instance.new( "Part" , Character) |
20 | x.CFrame = Torso.CFrame * CFrame.new( 0 ,- 5 ,- 5 ) |
22 | x.BrickColor = BrickColor.new( "Teal" ) |
23 | x.Size = x.Size + Vector 3. new( 1 , 1 , 1 ) |
27 | x.Material = "Concrete" |
28 | local s = Instance.new( "ParticleEmitter" , x) |
32 | s.VelocitySpread = 100000 |
40 | Mouse.KeyUp:connect( function (key) |
47 | Mouse.KeyDown:connect( function (key) |
52 | RS.C 0 = RS.C 0 *CFrame.Angles( 0 , 0 , 5 ) |
53 | LS.C 0 = LS.C 0 *CFrame.Angles( 0 , 0 ,- 5 ) |