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

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

Asked by 4 years ago
Edited 4 years ago

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!

0
I'd recommend using .Magnitude to .Position on line 9 and the ) at the end of line 9 greatneil80 2647 — 4y
0
@greatneil80 Explain that? LuckyOnes187 39 — 4y
0
see my answer for more deatil royaltoe 5144 — 4y
0
detail royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
0
With this, would I be doing "until magnitude > 0"? LuckyOnes187 39 — 4y
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? royaltoe 5144 — 4y
0
The script is trying to make a helicopter move to one side of the map, then move to the other side, repeatedly. LuckyOnes187 39 — 4y
0
I'll edit my response to show you a way you can do it without repeat wait. royaltoe 5144 — 4y
View all comments (14 more)
0
Oh okay, thanks. LuckyOnes187 39 — 4y
0
edited royaltoe 5144 — 4y
0
Wait, can't I just do "while true do if (condition) then break end"? LuckyOnes187 39 — 4y
0
yea there's multiple ways to do it royaltoe 5144 — 4y
0
you could also say while(condition)do end -- loops until the condition is false royaltoe 5144 — 4y
0
pls click answered if this works royaltoe 5144 — 4y
0
I will test this, it looks like it will work splendidly. LuckyOnes187 39 — 4y
0
Line 13: Unable to cast double to CoordinateFrame LuckyOnes187 39 — 4y
0
what are the values in the datastore? royaltoe 5144 — 4y
0
oops forgot CFrame.new royaltoe 5144 — 4y
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 royaltoe 5144 — 4y
0
WORKS LuckyOnes187 39 — 4y
0
kk good. royaltoe 5144 — 4y
0
also instead of script.Parent.X, script.Parent.CFrame.X but i think you figured that out royaltoe 5144 — 4y
Ad

Answer this question