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

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

Asked by 4 years ago

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'

0
wow i can't believe i didn't know that back then catsalt29 57 — 4y

2 answers

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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)
0
lmao raid6n 2196 — 4y
0
i got error:PlayerGui is not a valid member of Model Cats767_99 -68 — 4y
0
How about now? nikoviking 236 — 4y
0
Thanks!!! Cats767_99 -68 — 4y
View all comments (7 more)
0
how childish for sownvoting my answer for no reason, i only downvoted it because it was previously wrong raid6n 2196 — 4y
0
wasn't me Cats767_99 -68 — 4y
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. nikoviking 236 — 4y
0
lmao raid6n 2196 — 4y
0
how about we both remove the downvote and go on with our day raid6n 2196 — 4y
0
sure nikoviking 236 — 4y
0
ok raid6n 2196 — 4y
Ad
Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)

Answer this question