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

Why does my script show a gui for all the players?

Asked by 4 years ago
Edited 4 years ago

I need to make a gui that becomes visible when someone touches a part. But for some reason, if one player touches the part, the gui becomes visible for everyone. There are no errors at all.

local player = game.Players.LocalPlayer
game.Workspace.Shop.HitBox.Touched:Connect(function()
    if player.Character:FindFirstChild("Humanoid") and player then
        script.Parent.ShopFrameSelectionShadow.Visible = true
        script.Parent.ShopFrameSelection.Visible = true
    end
end)
0
You're forgetting one of the most important things! GUIs should always use a localscript I recommend you redo this whole thing under a localscript under StarterGui. 2Loos 168 — 4y

2 answers

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

you're not checking to make sure that the part that touched the shop was actually part of the player's character, meaning that ANY part that touches the shop will open the gui

you can simply check if the part's parent is the player's character to fix it

local player = game.Players.LocalPlayer
game.Workspace.Shop.HitBox.Touched:Connect(function(hit)
    if player.Character and hit.Parent == player.Character then
        script.Parent.ShopFrameSelectionShadow.Visible = true
        script.Parent.ShopFrameSelection.Visible = true
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

Yes, you might have coded it correctly, but it’s in a script. If you want something to show up for a local player than you must use a Local Script. What you need to do is put a local script were the script was, re-script the Local Script (I’m not sure if the script that you currently have in the Script will work if you transfer title to the Local Script, if it does tell me I’m interested). Even if the current script doesn’t work play around with it if you need anymore help just ask. Good luck.

Answer this question