``I've been trying to Change Visible on a Frame when a player touches a part but its giving me this error and i don't know why.
The Error
Workspace.DetectPart.OpenScript:10: attempt to index local 'EnableShop' (a nil value)
the script is a global script
here is my script
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid")and game.Players:GetPlayerFromCharacter(hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.parent) if player.OnPart.Value == false then player.OnPart.Value = true local EnableShop = player.PlayerGui:FindFirstChild("EnableShop") EnableShop.Frame.Visible = true end end end)
I've tried many different ways and i cant figure it out :(
This might help,
If you have FE a.k.a. Filtering Enabled then it won't work because the game can't get to game.Players in a server script.
Also try adding a wait(4) right at the top this is just a test it won't be there forever
If FindFirstChild
doesn't find a child with the provided name, it'll return nil. I would recommend using WaitForChild
instead, as it's possible the child hasn't yet been parented to the playergui by the time that line is reached.
E: Actually, it appears as if you're trying to read the content's of a player's playergui, which can't be done on the server. I originally thought you were using a localscript, however this doesn't appear to be the case.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.parent) if player.OnPart.Value == false then player.OnPart.Value = true local EnableShop = player.PlayerGui:WaitForChild ("EnableShop") EnableShop.Frame.Visible = true end end end)