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