Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to compare number with userdata error?

Error: "Attempt to compare number with userdata" Line of error: 4

Help please?

script.Parent.Touched:Connect(function(Hit)
	local PlayerChar = Hit.Parent
	local Player = game.Players:GetPlayerFromCharacter(PlayerChar)
if Player.leaderstats.RDCash > 400 then
	print("H")
	local Volt = game.Lighting.VoltBikeBlue:Clone()
	Volt.Parent = workspace
	print("Purchased!")
else 
	print("Not Enough Money!")
end
end)

2 comments

0

RDCash.Value

0

i think you are missing a .Value after "if Player.leaderstats.RDCash" at line 4.

1 answer

✓ Accepted answer
if Player.leaderstats.RDCash > 400 then

The problem here was that you tried to compare the number 400 to the IntValue itself, when rather you want to compare it to the value of this IntValue.

if Player.leaderstats.RDCash.Value > 400 then

Another problem with your script is that you aren't checking if Hit was actually the player, you should wrap the code in an if statement and check if the parent of Hit has a Humanoid, then check if the parent of Hit is a Player.

This discussion is preserved as it was. New answers, comments, and votes are closed.