Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

5 comments

0

"global script"

0

its a global scipt

0

What's OnPart?

0

its a Bool Value inside player so that the script only hapens once

0

Oh you can make that a normal variable in the script like, noSpam = false

2 answers

✓ Accepted answer

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

12 comments

0

At the top and why has mine been down voted??

0

idk

0

k i put the wait after Line 1 nothing diferent hapend

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

0

Did you wait 4 seconds after the game loaded ?

1

no i dint think that that was what you ment

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

0

Ya nothing Different

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

0

Filtering Enabled is on and the Gui is enabled but the the frame is not Active should that be on?

0

Yeah you should see what works best but with FE you're going to have to use remote event unfortunately

0

ok

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)


4 comments

0

Yeah

0

Infinite yield possible on 'Players.mrduckywucky4.PlayerGui:WaitForChild("EnableShop")'

0

Oh noo! Don't be afraid we'll fight this problem together as a team!

0

Is it possible you're not parenting the "EnableShop" screengui to the playergui?

This discussion is preserved as it was. New answers, comments, and votes are closed.