So, the logic behind this script is that it is in a brick. When a player steps on the brick, it creates a cloned gui from lighting and places it in the player's PlayerGui. There is a bool value in the player so that if the gui is already opened, it won't clone it again. The problem is that the script breaks at line 7 giving the error "Workspace.Teleport Place 1.Part.Script2:7: attempt to index field 'LocalPlayer' (a nil value)" In my previous experiences, I've always had trouble with "nil values". What is the problem with this script?
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
if game.Players.LocalPlayer.TeleP1.Value == false then
game.Lighting.TeleP1:clone().Parent = game.Players.LocalPlayer.PlayerGui
game.Players.LocalPlayer.TeleP1.Value = true
else
print("Already Open.")
wait(1)
end
end
end
script.Parent.Touched:connect(onTouch)

1 comment
LocalPlayer will only work in a LocalScript. LocalScripts will only work in the Player's Backpack, PlayerGui, Character, or PlayerScripts.