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

How to i make a gui visible when a part is touched?

script: script.Parent.Touched:Connect(function(hit) game.Players.LocalPlayer.PlayerGui.ShopGui.Frame.Visible = true end)

error: Workspace.Sell.Script:2: attempt to index nil with 'PlayerGui'

1 comment

0

wow i can't believe i didn't know that back then

2 answers

✓ Accepted answer

This is a script on the part, so there is no such thing as LocalPlayer. Only in LocalScripts.

Try this instead:

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	player.PlayerGui.ShopGui.Frame.Visible = true
end)

11 comments

0

lmao

0

i got error:PlayerGui is not a valid member of Model

0

How about now?

0

Thanks!!!

0

how childish for sownvoting my answer for no reason, i only downvoted it because it was previously wrong

0

wasn't me

0

You copied my answer, raid6n. I made a very simple mistake, you downvoted me without telling me why and duplicated it, instead of making a simple comment correcting the ancestry of PlayerGui. You're the one being childish.

0

lmao

0

how about we both remove the downvote and go on with our day

0

sure

0

ok

You cannot use LocalPlayer in a server script, but you can use getplayerfromcharacter(hit.parent).

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    player.PlayerGui.ShopGui.Frame.Visible = true
end)

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