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

getting This Error OpenScript:10: attempt to index local 'EnableShop' (a nil value) dont know why?

Asked by 5 years ago
Edited 5 years ago

``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 :(

0
"global script" User#19524 175 — 5y
0
its a global scipt Nooberton_1 9 — 5y
0
What's OnPart? xxcoordinatorxx 135 — 5y
0
its a Bool Value inside player so that the script only hapens once Nooberton_1 9 — 5y
0
Oh you can make that a normal variable in the script like, noSpam = false xxcoordinatorxx 135 — 5y

2 answers

Log in to vote
-1
Answered by 5 years ago

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

0
At the top and why has mine been down voted?? xxcoordinatorxx 135 — 5y
0
idk Nooberton_1 9 — 5y
0
k i put the wait after Line 1 nothing diferent hapend Nooberton_1 9 — 5y
0
I mean did it work for you at least and i didn't get a reason for why mines been down voted kinda sad xxcoordinatorxx 135 — 5y
View all comments (8 more)
0
Did you wait 4 seconds after the game loaded ? xxcoordinatorxx 135 — 5y
1
no i dint think that that was what you ment Nooberton_1 9 — 5y
0
Oh no add the script and then wait after the game loads because thst script meana ot won't run till it's been 4 seconds lol xxcoordinatorxx 135 — 5y
0
Ya nothing Different Nooberton_1 9 — 5y
0
Is the error the same? If it is then you need to check if FE is on or off in the workspace properties and also check your GUI lol xxcoordinatorxx 135 — 5y
0
Filtering Enabled is on and the Gui is enabled but the the frame is not Active should that be on? Nooberton_1 9 — 5y
0
Yeah you should see what works best but with FE you're going to have to use remote event unfortunately xxcoordinatorxx 135 — 5y
0
ok Nooberton_1 9 — 5y
Ad
Log in to vote
0
Answered by
systack 123
5 years ago
Edited 5 years ago

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)


0
Yeah xxcoordinatorxx 135 — 5y
0
Infinite yield possible on 'Players.mrduckywucky4.PlayerGui:WaitForChild("EnableShop")' Nooberton_1 9 — 5y
0
Oh noo! Don't be afraid we'll fight this problem together as a team! xxcoordinatorxx 135 — 5y
0
Is it possible you're not parenting the "EnableShop" screengui to the playergui? systack 123 — 5y

Answer this question