Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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:

01-- Get the player, character, and the players gui
02local player = game.Players.LocalPlayer
03local char = player.CharacterAdded:wait()
04local hum = char:WaitForChild("Humanoid")
05local gui = player:WaitForChild("PlayerGui")
06 
07-- Delay
08    wait(1)
09 
10-- Parent the script to StarterGui and set the properties of wall
11    script.Parent = gui
12    wall = Instance.new("Part")
13    wall.Name = "wall"
14    wall.Shape = "Cylinder"
15    wall.Rotation = Vector3.new(0, 0, -90)
View all 52 lines...

2 answers

Log in to vote
0
Answered by 8 years ago

The problem is that Local Scripts only work in certain areas. The local player can only be found inside the Player, but Workspace isn't a player so it returns 'nil' as a way of saying "Hey I am not inside a Player!"

Instead of using LocalPlayer...I would just do a regular script in the workspace with the 'PlayerTouched' event... it will give you the player touching the wall so that the event automatically sets wh touched it.

Hope this helps!

Ad
Log in to vote
0
Answered by 8 years ago

repeat wait() until game.Players.LocalPlayer

Answer this question