I have made the shop GUI with in-game currency.
The problem is when someone touches the part that opens GUI, everyone in server can see this GUI and I don’t want that.
edit:
In the mean time, it has to do with your shopMenu() function. Since you did a .Touched event for the function call, you can actually pass an arugment that is the part that touched.
An example, though, is like the following:
function shopMenu(part)
-- check if part is part of a NPC/player
if part.Parent:FindFirstChild("Humanoid") then
-- check if player
if game.Players:FindFirstChild(part.Parent.Name) then
local Player = game.Players[part.Parent.Name]
-- code
end
end
end
First off we need to put the script in StarterPlayer > StarterCharacterScripts.
The next issue is every time the part is touched we are never checking if it’s our player that touched it, so if something touches it then we are going to open the shop not matter what because we don’t check what/who touched the part.
To fix this we can do
local Character = game.Players.LocalPlayer.Character
local function shopMenu(Hit)
if canShop and Hit.Parent == Character then
canShop = false
Character.Humanoid.WalkSpeed = 0
frame.Visible = true
end
end
openPart.Touched:Connect(shopMenu)
edit:
While @Trayeus way can be used, I would go with my way as it can be more reliable at some times mainly because it does not depend on the name of the object.
Either would work. Your’s is more geared toward a LocalScript like the OP wants, but mine can be used on either a LocalScript or a Server Script. It is matter of which way you want to use it. I use this way both locally and on the server-side and have never had an issue with reliability.
By reliability I mean (this does only applies to some games) if your planning on having some AI (aka humanoids/characters or just objects with a humanoid and name) being the names of players then it would register as it being touched. But yes either way would work in this case.