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

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

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)

1 comment

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.

2 answers

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)

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.

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