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

How can I fix the "attempt to compare two userdata values" error?

Asked by 7 years ago
Edited 7 years ago

I keep getting the error "attempt to compare two userdata values" with this part of my script:

for _,v in pairs(children) do
    if v.Position >= game.Workspace.dud.Position then
        v:Destroy()
    end
end

As soon as I change == to >= it comes up with that error. Please explain why and tell me how to fix it.

0
What are you trying to compare? thesit123 509 — 7y
0
Obviously v.Position and game.Workspace.dud.Position MiguRB 60 — 5y

1 answer

Log in to vote
4
Answered by
Newrown 307 Moderation Voter
7 years ago
Edited 7 years ago

The problem here is that you cannot ask the program to check if a vector is bigger than the other, or a vector is smaller than the other.

Though a way to fix it would be to refer to each axis on its own.

So it would look something like this:

for _,v in pairs(children) do
    if v.Position.Y >= game.Workspace.dud.Position.Y then -- assuming you want to compare the y-axis
        v:Destroy()
    end
end

Hope it helped!

0
Thank you. joshmatt2244 28 — 7y
0
how do u do that with udim2 TheOnlySmarts 233 — 6y
Ad

Answer this question