Proximity Prompt GUI SHOP *not working*

Hello, my Roblox Gui Shop opens when I single player play test it using the Proximity Prompt but whenever I play test with multiple people it doesn’t work. I have a remote event in replicatedstorage named “openShop”, please tell me if this is wrong because I do not know if I did this correctly.

Script in side proximity prompt:

game.Players.PlayerAdded:Connect(function(player)
	local replicatedStorage = game:GetService("ReplicatedStorage")
	local openShopEvent = replicatedStorage:FindFirstChild("openShop")

	local openPrompt = script.Parent

	local function openShop (player)
		openShopEvent:FireClient(player)
	end

	openPrompt.Triggered:Connect(openShop)
end)

local script in StarterGui:

local replicatedStorage = game:GetService("ReplicatedStorage")
local openShopEvent = replicatedStorage:FindFirstChild("openShop")

local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui:FindFirstChild("shopGui")

local function openShop ()
	if playerGui.Enabled == false then
		playerGui.Enabled = true
	else
		playerGui.Enabled = false
	end
end

openShopEvent.OnClientEvent:Connect(openShop)

Proximity prompt’s Triggered event already gives the player who triggered it. You don’t need to re-connect it for every player. Removing the PlayerAdded connection from your Script would suffice

local replicatedStorage = game:GetService("ReplicatedStorage")
local openShopEvent = replicatedStorage:WaitForChild("openShop")

local openPrompt = script.Parent

local function openShop (player)
	openShopEvent:FireClient(player)
end

openPrompt.Triggered:Connect(openShop)
1 Like

Thank you very much! I am trying to improve my scripting and I was a little confused on how to get the player from a regular script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.