Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] Attempt to compare two userdata values, but I thought neither was a userdata value?

Not sure why it's saying that, or what a userdata value is. I tried researching, but nothing had my answer. What am I doing wrong here?

Thanks to royaltoe, this question was solved! Thank you!

4 comments

0

I'd recommend using .Magnitude to .Position on line 9 and the ) at the end of line 9

0

@greatneil80 Explain that?

0

see my answer for more deatil

0

detail

1 answer

✓ Accepted answer

#With repeat wait You're comparing a vector3 with another vector3 which you can't do.

what you can do is get the magnitude of the hit box and the vector3

magnitude = (hitbox.position- vector3.new(vector3 position goes here)).magnitude

and see if the magnitude is positive (the hitbox position is greater than the vector3() you specified or if it's negative, (less than the position specified)

#Without repeat wait (for loop):

while true do
	--Make helicopter go forward until it reaches the end of the map

	local startX = script.Parent.CFrame.X

	for i = startX , 97, 0.1 do
		yPos = script.Parent.Y
		zPos = script.Parent.Z
		 script.Parent:SetPrimaryPartCFrame(i, yPos,zPos)
      		wait(0.005)
	end
	 
	script.Parent.hitbox.Orientation = Vector3.new(0, 0, 0)

	--Make the helicopter go back to the start of the map
	startX = script.Parent.CFrame.X
	
	for i = startX , -97, -0.1 do
		yPos = script.Parent.Y
		zPos = script.Parent.Z
		 script.Parent:SetPrimaryPartCFrame(i, yPos,zPos)
      		wait(0.005)
	end

    	script.Parent.hitbox.Orientation = Vector3.new(0, 180, 0)
   wait(0.05)
end

#Without repeat wait (while loop)

while true do
	--Make helicopter go forward until it reaches the end of the map

	local xPos = script.Parent.CFrame.X

	while(xPos < 97)do
		xPos = xPos  + 1
		yPos = script.Parent.Y
		zPos = script.Parent.Z
		 script.Parent:SetPrimaryPartCFrame(CFrame.new(xPos, yPos,zPos))
      		wait(0.005)
	end
	 
	script.Parent.hitbox.Orientation = Vector3.new(0, 0, 0)

	--Make the helicopter go back to the start of the map
	
	local xPos = script.Parent.CFrame.X

	while(xPos > -97)do
		xPos = xPos  - 1
		yPos = script.Parent.Y
		zPos = script.Parent.Z
		 script.Parent:SetPrimaryPartCFrame(CFrame.new(xPos, yPos,zPos))
      		wait(0.005)
	end

    	script.Parent.hitbox.Orientation = Vector3.new(0, 180, 0)
   wait(0.05)
end

18 comments

0

With this, would I be doing "until magnitude > 0"?

0

sure, but it's not the best idea to use repeat until. there's always a better solution. repeat can pause your script indefinitely constantly waiting which you don't want. what is your script trying to do exactly?

0

The script is trying to make a helicopter move to one side of the map, then move to the other side, repeatedly.

0

I'll edit my response to show you a way you can do it without repeat wait.

0

Oh okay, thanks.

0

edited

0

Wait, can't I just do "while true do if (condition) then break end"?

0

yea there's multiple ways to do it

0

you could also say while(condition)do end -- loops until the condition is false

0

pls click answered if this works

0

I will test this, it looks like it will work splendidly.

0

Line 13: Unable to cast double to CoordinateFrame

0

what are the values in the datastore?

0

oops forgot CFrame.new

0

should work now. i just forgot to put the cframe values in CFrame.new() so roblox got confused because the parameters of SetPrimaryPartCFrame were three numbers instead of a CFrame value

0

WORKS

0

kk good.

0

also instead of script.Parent.X, script.Parent.CFrame.X but i think you figured that out

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