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

How do I match a number with Tables?

Asked by 6 years ago

Hi.

What I am trying to do right now is that I want to match the Humanoid Root Part's position with the table of values I have.

If the value is matched with table, then it will break the while true do loop.

I don't think I can use generic for loop for this because I have to check 3 things simultaneously. So how would I go on to do this?

I tried doing GetChildren() before hand but it gave me table error. I don't know how to do this. Please help me.

Here is my code if you do need it.

local TargetX = {
    83, 84, 85, 86, 87, 88
}

local TargetY = {
    3
}

local TargetZ = {
    -94, -95, -96, -97, -98
}

while true do 
    local XPos = HumanoidRootPart.Position.X
    local YPos = HumanoidRootPart.Position.Y
    local ZPos = HumanoidRootPart.Position.Z

    print(RoundNumber(XPos), RoundNumber(YPos), RoundNumber(ZPos))
    wait()

    local XChild = TargetX:GetChildren()
    local YChild = TargetY:GetChildren()
    local ZChild = TargetZ:GetChildren()

    if RoundNumber(XPos) == XChild and RoundNumber(YPos) == YChild and RoundNumber(ZPos) == ZChild then 
        print("Match Found")
        break
    end
end

The RoundNumber is my rounding function. There is nothing wrong with that btw.

0
You can try using coroutines maybe? Vid_eo 126 — 6y
1
To solve this, You could make a function (or three, depends on your arguments) to look through each table. You **can** use a generic for loop to iterate through the table, then return true if any of the values is a match. To finish it off in your final if statement, put calls to each of the functions (or 1 function, depends on your arguments), separated with `and`, and you'll be fine. Shawnyg 4330 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local TargetX = {
    83, 84, 85, 86, 87, 88
}

local TargetY = {
    3
}

local TargetZ = {
    -94, -95, -96, -97, -98
}

while true do 
    local XPos = HumanoidRootPart.Position.X
    local YPos = HumanoidRootPart.Position.Y
    local ZPos = HumanoidRootPart.Position.Z

    print(RoundNumber(XPos), RoundNumber(YPos), RoundNumber(ZPos)) -- XPos+0.5:floor() works too
    wait()

    for _, x in pairs(TargetX) do
            for i, y in pairs(TargetY) do
                for m, z in pairs(TargetZ) do
                    if x == (XPos+0.5:floor()) and y == (YPos+0.5:floor()) and z == (ZPos+0.5:floor()) then
                    WillBreak = true
    add more ends
end
if WillBreak then break -- might have to move this idk too lazy to check.
end
Ad

Answer this question