``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
01 | script.Parent.Touched:connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) and game.Players:GetPlayerFromCharacter(hit.Parent) then |
03 | local player = game.Players:GetPlayerFromCharacter(hit.parent) |
04 | if player.OnPart.Value = = false then |
05 |
06 | player.OnPart.Value = true |
07 |
08 | local EnableShop = player.PlayerGui:FindFirstChild( "EnableShop" ) |
09 |
10 | EnableShop.Frame.Visible = true |
11 | end |
12 | end |
13 | 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.
01 | script.Parent.Touched:connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) and game.Players:GetPlayerFromCharacter(hit.Parent) then |
03 | local player = game.Players:GetPlayerFromCharacter(hit.parent) |
04 | if player.OnPart.Value = = false then |
05 | player.OnPart.Value = true |
06 | local EnableShop = player.PlayerGui:WaitForChild ( "EnableShop" ) |
07 | EnableShop.Frame.Visible = true |
08 | end |
09 | end |
10 | end ) |