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)
-- Regular script function onTouch(part) local human = part.Parent:FindFirstChild("Humanoid") local plr = game.Player:GetPlayerFromCharacter(part.Parent) if human and plr then if plr.TeleP1.Value == false then game.Lighting.TeleP1:clone().Parent = plr.PlayerGui plr.TeleP1.Value = true else print("Already Open.") wait(1) end end end script.Parent.Touched:connect(onTouch)
findFirstChild
to FindFirstChild
deprecated
, and/or it's just bast to use capital letters.GetPlayerFromCharacter
functionWhile Filtering Enabled
is Enabled, scripts can't access PlayerGui
. To make this FE compatible, use RE or use a Local Script
in StarterPack
or something, with the proper variables re-defined without using .Parent of course.
I hope I helped!
Good Luck!
put it in a localscript