Proximityprompt only working once

so i made the game trigger a shop to be visible whenever the proximityprompt is triggered. i also have a close button on the shop so that it can close. however, if i choose to open the shop again when its closed, it just does not do anything

my script:

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	player.PlayerGui.GameUI.Shop.Visible = true
	player.Character.HumanoidRootPart.Anchored = true
end)
4 Likes

Can you please also show the script located in the close button? Thanks.

button = script.Parent
player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	player.PlayerGui.GameUI.Shop.Visible = false
	player.Character.HumanoidRootPart.Anchored = false
end)

the gui closes when the button is pressed but once it has been open the first time, the shop just doesnt open again. i tested something on the serverscript where i made it print text after it anchors the character and it only prints the text and ignores the rest of it

Are you using a proximity prompt or a click detector?

Is this located in a server script? If it is, you can’t find LocalPlayer using server scripts.

im using a proximityprompt not a click detector

the one with localplayer in it is a localscript

Maybe because you used a server script to make it visible and when you used the local script it closed in on your client not the server. So the server still thinks the gui is open.

2 Likes

but i thought guis are purely stored onto the client

Any changes done on the client do not replicate to the server.

1 Like

i fixed it using remote events

script under shop:

event = game.ReplicatedStorage:WaitForChild("closeshop")

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	player.PlayerGui.GameUI.Shop.Visible = true
	player.Character.HumanoidRootPart.Anchored = true
end)

local function closeshop(player)
	player.PlayerGui.GameUI.Shop.Visible = false
	player.Character.HumanoidRootPart.Anchored = false
end

event.OnServerEvent:Connect(closeshop)

localscript:

button = script.Parent
player = game.Players.LocalPlayer
event = game.ReplicatedStorage:WaitForChild("closeshop")

button.MouseButton1Click:Connect(function()
	event:FireServer(player)
end)
2 Likes