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

attempt to compare two userdata values?

Asked by 7 years ago

The goal is that when a player presses e, they will move to the nearest grip point, and "climb" up a wall.

When the player presses their e key, this error occurs Players.Player1.Backpack.LocalScript:9: attempt to compare two userdata values

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function FindNearestGrip()
    local grips = game.Workspace:FindFirstChild("Grips", true):GetChildren()
    table.sort(grips, function(a, b)
    local dstA = (a.Position - player.Character.HumanoidRootPart.Position).magnitude
    local dstB = (b.Position - player.Character.HumanoidRootPart.Position).magnitude
return a < b
    end)
    return grips[1]
end

mouse.KeyDown:connect(function(key)
    if key == 'e' then 
        FindNearestGrip()
    end 
end)

1 answer

Log in to vote
0
Answered by 7 years ago

a and b are Vector3s. You cannot compare them using <, which you do on line 9 (hence the error). Instead, you probably wanted dstA < dstB.

Of course, even with that fixed, you still need to do something with the result on line 16. The first step is undoubtedly to have the character walk there. Possibly, attempting to walk past the grip location (if approaching it from the right angle) might cause the character to climb (though I have not tested this).

Ad

Answer this question