Hi I’m currently working on a Shop Gui but somehow when there is more than 1 player it will automatically pay double like this:
It is launched from a Local Script and activated in the Server Script.
Local Script:
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Rubles.Value >= 10 then
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent:FireServer()
script.Parent.Parent.Parent.Parent.Parent.Parent.BobGeneralStore.Enabled = false
end
end)
Please add debugging prints to pinpoint where and which code executes twice.
Example:
Local Script
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
print("Clicked.")
if Player.leaderstats.Rubles.Value >= 10 then
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent:FireServer()
print("Fired event.")
script.Parent.Parent.Parent.Parent.Parent.Parent.BobGeneralStore.Enabled = false
end
end)
Server Script
local Tool = game.ReplicatedStorage.BusinessItems.JokeGun
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent.OnServerEvent:Connect(function(Player)
print("Executing event to: ", Player)
Player.leaderstats.Rubles.Value -= 10
Tool:Clone().Parent = Player.Backpack
end)
Then follow up with a result of the output window so that we can hopefully find a solution. If this does not clarify anything, at least it’s a clue richer to finding the issue.
Using the player-added function is a bad idea; every player that will now join is now considered the local player, which is why it is going to the wrong person. The remote event itself will pass to the player who pressed the button. Player 2 was the last to join, which is why Player 2 got the gun and not Player 1.
Then the issue is more than just a coding error. There is a miscommunication in the RemoteEvent being fired. Perhaps a different script is picking up signals being sent to the server. More than this I can not help with the limited access to find out such issues.
You’re receiving a Player variable from your ServerScript’s connection.
Make a new Remote, ServerScript, and ClientScript for each new PlayerAdded (Important to prevent exploiters from making other players buy things) and then simply take the new player’s player and pass it to the ServerScript.
Upon the event being fired, you can check if the Player variable from the event is the same as the Player variable passed from when the new scripts and events are made. Then, do your leaderboard stuff with either variable.