CheckPurchaseUserdataError.rbxl (18.8 KB)
Hello all! I recently became a member of the Roblox Developer Forum so I might not know all the steps I need to take in order to make debugging my code convenient for you all.
I recently ran into a really interesting problem in my game.
I was creating a shop menu, and I wanted to check whether or not the player has enough “Coins” in their leaderstats to purchase the said amount. I noticed that if someone was exploiting and changed the number of their coins locally, the transaction would go through the system. To eliminate the problem, I have decided to create a remote function under Replicated Storage that would check to see whether the player has enough coins (on the server-side), and would return true if they do.
In the Server Script…
--In a server script under ServerScriptService
--Check to see whether it is possible for the user to purchase the item )
--(on the server-side to prevent exploiting)
--"fee" is the amount required to purchase Item
checkEligibility.OnServerInvoke = function(player, fee)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
print(coins.Value) --IT PRINTS THE CORRECT AMOUNT BUT WHY CANT IT COMPAIR!?!?!?!
if coins.Value >= fee then --error is here
return true
else
return false
end
end
And in the Client Script…
if checkEligibility:InvokeServer(game.Players.LocalPlayer, price) then
--continue to purchase
else
--continue to do the course of action that will notify the player that they couldn't purchase the item
end
Whenever I invoked this function, I would get an error stating: “16:06:26.033 - ServerScriptService.Script:26: attempt to compare userdata with number”
What exactly is going on, and how do I fix this problem?