How to make roblox wait for local player?
Asked by
8 years ago Edited 8 years ago
So I have a script that works fine while It's in the players startergui, it creates a giant laser that moves around and kills anyone it touches, the problem is I want it to start off in the workspace and then be moved into the local players startergui. For some reason, while it's not already in startergui, I get an error that says "Workspace.Script:3: attempt to index local 'player' (a nil value)". I think it's because Roblox hasn't loaded the local player yet. Can someone Please tell me how to fix this issue!?
Script:
02 | local player = game.Players.LocalPlayer |
03 | local char = player.CharacterAdded:wait() |
04 | local hum = char:WaitForChild( "Humanoid" ) |
05 | local gui = player:WaitForChild( "PlayerGui" ) |
12 | wall = Instance.new( "Part" ) |
14 | wall.Shape = "Cylinder" |
15 | wall.Rotation = Vector 3. new( 0 , 0 , - 90 ) |
17 | wall.Size = Vector 3. new( 400 , 8 , 8 ) |
18 | wall.Transparency = 0.7 |
19 | wall.Color = Color 3. new( 255 , 0 , 0 ) |
20 | wall.CanCollide = false |
21 | wall.Material = "Neon" |
23 | wall.CFrame = char.Torso.CFrame + char.Torso.CFrame.lookVector * 5 |
24 | wall.CFrame = wall.CFrame * CFrame.Angles( 0 , 0 , 1 / 2 * math.pi) |
25 | wall.Parent = game.Workspace |
32 | local hum = hit.Parent:FindFirstChild( "Humanoid" ) |
38 | wall.Touched:connect(hited) |
41 | wall.CFrame = wall.CFrame + char.Torso.CFrame.lookVector * 5 + Vector 3. new( 0 , 0 , - 1 ) |
49 | if hum.Health = = 0 then |