Attempt to compare userdata to number, WHAT?

		for _, s in ipairs(Table) do
			local Number = s.Y -- Number is a Vector3 value, s.Y is the Y coordinate
			print(Number) -- this WORKS and returns 7.5 in my case
			if (Number > HighestValue and s) then -- error line, HighestValue equals to 0 
				HighestValue = Number
			end
		end

This returns an error, however I do not use any userdata…

2 Likes

Try HighestValue.Value. I’m not totally sure this will work though.

HighestValue is a local variable.

Alright, can you explain what all of the variables are?

Try to add tonumber(s.Y), also you don’t need to add brackets in that conditional statement.

I have tried doing that, still counts it as userdata.

How exactly are you printing a string and getting 7.5 back?

3 Likes

HighestValue = 0, local variable
s is a table value inside an ipair loop, the table contains Vector3’s
s.Y is the y coordinate of the Vector3 position.

Want me to provide you the entire code?

And also, how does it even return a number, as Number is in quotes?

I still fail to see how you’d get a number from printing a string, but yes, that’d help.

Also, moon, exactly my point

Oh yeah, sorry about that. I tested it out with print(Number) and it didnt work, I only added it to show that I tried doing that, my bad. I will fix this right now.

Could you also possibly explain what this script will do?

By that I mean that the issue is still there and that it was just a typo.

Here is the entire script:

UIS.InputBegan:Connect(function(Key, Cant)
	if Key.KeyCode == Enum.KeyCode.Space and Cant == false and ClimbCd == false and Stun.Value == 0 and Falling.Value == true then
		spawn(function()
			ClimbCd = true
			wait(3)
			ClimbCd = false
		end)
		local RegionSize = Vector3.new(3,3,3)
		local RegionPos = RootPart.Position + (RootPart.CFrame.LookVector * 0.6) + Vector3.new(0,2,0)
		local Region = Region3.new(RegionPos-(RegionSize/2),RegionPos+(RegionSize/2))
		local Parts = workspace:FindPartsInRegion3(Region,Character,20)
		local FinalPosition
		local Table = {}
		local HighestValue = 0
		for _, v in ipairs(Parts) do
			local Top = v.CFrame * CFrame.new(0,v.Size.Y/2,0)
			local TopMin = v.CFrame * CFrame.new(-v.Size.X/2,v.Size.Y/2,-v.Size.Z/2)
			local TopMax = v.CFrame * CFrame.new(v.Size.X/2,v.Size.Y/2,v.Size.Z/2)
			local MinX = TopMin.X
			local MaxX = TopMax.X
			local MinZ = TopMin.Z
			local MaxZ = TopMax.Z
			local PosX = RegionPos.X
			local PosZ = RegionPos.Z
			local X = math.clamp(PosX, MinX, MaxX)
			local Z = math.clamp(PosZ, MinZ, MaxZ)
			local Y = Top.Y
			local Position = Vector3.new(X,Y,Z)
			local Raycast = Ray.new(Position, Position+Vector3.new(0,0.5,0))
			local RayPart = workspace:FindPartOnRay(Raycast,Character)
			if RayPart == nil then
				table.insert(Table, Position)
			end
		end	
		for _, s in ipairs(Table) do
			local Number = s.Y -- Number is a Vector3 value, s.Y is the Y coordinate
			print("Number") -- this WORKS and returns 7.5 in my case
			if (Number > HighestValue and s) then -- error, HighestValue equals to 0 
				HighestValue = Number
			end
		end
		FinalPosition = Vector3.new(HighestValue)
		if FinalPosition ~= nil then
			local Distance = (RegionPos - FinalPosition).magnitude
			if Distance <= 1.5 then
				local BV = Instance.new("BodyPosition")
				BV.Parent = RootPart
				BV.MaxForce = Vector3.new(36000,36000,36000)
				BV.Position = RootPart.Position+RootPart.CFrame.LookVector*2+Vector3.new(0,5,0)
				BV.P = 32000
				game.Debris:AddItem(BV, 1.1)
				ClimbAnim:Play()
				game.ReplicatedStorage.Events.ClimbSound:FireServer()
				Humanoid.AutoRotate = false
				ToggleStun(1.1)
				wait(0.55)
				Humanoid.AutoRotate = true
			end
		end
	end
end)

the entire script worked and i just wanted to enhance it, by the way.
the script makes a region3, then finds all the parts within the region3, finds their upper face, then gets the closest point to you, then if the point is close enough, your character will climb the part. Everything worked but if there were 2 parts on top of each other it would randomly pick the point, and i want to make it so that it doesnt pick it randomly but rather picks the highest point.

Try if (Number >= Highestvalue and s) then

Well, that doesn’t really help anything, because you’re still comparing a number with a userdata.

Nope, can’t do that. The math matters to me a lot in this case.

I’ve had this sort of issue before, and this usually fixes it, so I thought OP should might as well try it.

I will try that but it probably wouldn’t work.