game:GetService('Players').PlayerAdded:Connect(function(player)
player.Backpack.ChildAdded:Connect(function(child)
if child.Name == 'Sparkling water.' and player.leaderstats['$DP'].Value < 20 then
player:Kick('a')
end
end)
end)
This sanity check fires for all players and whenever a new item is added to their backpack
I’m assuming you’re always checking the player’s balance on the client, so now that you’re checking it on the server as well, I think your code is fine as is. Depending on if the player can have duplicates, you could add a check verifying that the player is not trying to get more than they’re allowed. You’d of course have to stop the remote from being fired by the client script when the player has what they’re allowed.
This code would not have the desired effect as it would kick the player if they bought the item then had too little money. I’ll break the steps of logic down:
Player buys the item with 20 of their 37 $DP.
The server verifies that Player has enough money, subtracts 20 $DP from their balance, and gives the item.
ChildAdded fires and the connection function sees that Player has only 17 $DP, which is less than 20.
I gave it some more thought, and I think you’re right. Exploiting purchases won’t give you an advantage over other players especially since it subtracts from your balance anyway. Thanks!