Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
Is it running multiple times? MahadTheIronSword 98 — 5y
0
Try using an Debounce, and USE if and statements like ( if p.leaderstats.Points.Value > 150 then) cherrythetree 130 — 5y
0
Put a parameter in the remote event named "Player" and use that instead of the Player added parameter Despayr 505 — 5y
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. Rheines 661 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question