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

WHY DOES THIS KEEP ERRORING? saying user data is unable to compare?

Asked by 5 years ago
Part = script.Parent
BodyVelocity = Part.BodyVelocity
L = 'Touchpart'

Part.Touched:Connect(function(hit)
     if hit:FindFirstChild('StringValue').Value == 'RevertValue' then
        Neg = hit:FindFirstChild('Negative')
        Pos = hit:FindFirstChild('Positive')
        if BodyVelocity.Velocity < Pos.Value then
            BodyVelocity.Velocity = Neg.Value
        elseif
            BodyVelocity.Velocity > Neg.Value then
                BodyVelocity.Velocity = Pos.Value
        end

    end


end)

it keeps saying 14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number

14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number

14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number

I don't get why and what a user data is and why its erroring any fix

1 answer

Log in to vote
1
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

The Velocity property from the BodyVelocity object is a Vector3 userdata type. Userdata types include CFrame or BrickColor. I'm assuming that "Positive" is a NumberValue object, so technically you're comparing something that looks like:

if Vector3.new(0, 0, 0) < 123 then --example case

To fix this you could compare Positive.Value, and the other, to the read-only properties of the Vector3. So something like:

if BodyVelocity.Velocity.Y < Pos.Value then
    --run code if Y value is lower
elseif BodyVelocity.Velocity.Y > Pos.Value then
    --run code if Y value is greater
end

The top is just an example at what you're looking for. You do have access to the other immutable properties for a Vector3. You can see a list of them here.

Let me know if you need something explained or I had missed anything.

Ad

Answer this question