Sanity checks for Tools

I want to add sanity checks to this so exploiters can’t put the item into their backpack whenever they want, but I’m not sure what to add.

local itembought = game.ReplicatedStorage.sparkpurchase

itembought.OnServerEvent:Connect(function(player)
	if player.leaderstats["$DP"].Value >= 20 then
		player.leaderstats["$DP"].Value = player.leaderstats["$DP"].Value - 20
		game.ServerStorage:WaitForChild("Sparkling water."):Clone().Parent = player.Backpack
	else
		player:Kick("a")
	end
end)

2 Likes

Try this

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

Where would I fit this in the script?

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:

  1. Player buys the item with 20 of their 37 $DP.
  2. The server verifies that Player has enough money, subtracts 20 $DP from their balance, and gives the item.
  3. ChildAdded fires and the connection function sees that Player has only 17 $DP, which is less than 20.
  4. The player gets kicked for being too poor.

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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.