Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to compare number with userdata error?

Asked by 5 years ago

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)
0
RDCash.Value MooMooThalahlah 421 — 5y
0
i think you are missing a .Value after "if Player.leaderstats.RDCash" at line 4. splat_rt 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
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.

Ad

Answer this question