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 two userdata values?

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

✓ Accepted answer

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).

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