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!
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!
#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
With this, would I be doing "until magnitude > 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?
The script is trying to make a helicopter move to one side of the map, then move to the other side, repeatedly.
I'll edit my response to show you a way you can do it without repeat wait.
Oh okay, thanks.
edited
Wait, can't I just do "while true do if (condition) then break end"?
yea there's multiple ways to do it
you could also say while(condition)do end -- loops until the condition is false
pls click answered if this works
I will test this, it looks like it will work splendidly.
Line 13: Unable to cast double to CoordinateFrame
what are the values in the datastore?
oops forgot CFrame.new
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
WORKS
kk good.
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.
4 comments
I'd recommend using .Magnitude to .Position on line 9 and the ) at the end of line 9
@greatneil80 Explain that?
see my answer for more deatil
detail