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

Why does buying an item take away every player's points?

I made an item shop and when you buy something, a RemoteEvent gets called and it is supposed to take away the person who bought the item's points, but it takes away everyone's points and I don't know a solution to this

game.Players.PlayerAdded:Connect(function(p)
game.ReplicatedStorage.event2.OnServerEvent:Connect(function()
p.leaderstats.Points.Value = p.leaderstats.Points.Value - 150
end)
end)

4 comments

0

Is it running multiple times?

0

Try using an Debounce, and USE if and statements like ( if p.leaderstats.Points.Value > 150 then)

0

Put a parameter in the remote event named "Player" and use that instead of the Player added parameter

0

You have to separate both events. Do not put OnServerEvent inside PlayerAdded. As above, OnServerEvent has a player parameter so you use that instead.

1 answer

✓ Accepted answer

You should not use PlayerAdded's passed argument, but rather the argument passed by OnServerEvent (they're both a player, but the difference is that the player in PlayerAdded applies to any player that joined a game, and that can apply to every player in the game. The player argument passed by OnServerEvent is the player who triggered the RemoteEvent, which normally isn't every player).

Example:

game:GetService("ReplicatedStorage"):WaitForChild("event2").OnServerEvent:Connect(function(player)
    player.leaderstats.Points.Value = player.leaderstats.Points.Value - 150
end)

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