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

Using a table with a if function?

Asked by
danglt 185
5 years ago

how would i make it to use all of the formulas in te table

local m = game.Workspace.E
yes = {m.Circle,m.hallleave}
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Key)
    if Key.KeyCode == Enum.KeyCode.E and (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - yes.Position).magnitude <= 15 then
        print("Test Succesful")
    end
end)
1
?????? Amiaa16 3227 — 5y
0
what User#23365 30 — 5y
0
o i get it User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

im not so sure of what you want, but if you'd want to check the magnitude between each value in the array and the player's character you can iterate through the array. also you should be using local variables as the variable defined as the array is on the highest scope.

local thing = game.Workspace.E
local array = {m.Circle, m.hallleave}
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(key)
    if key.KeyCode = Enum.KeyCode.E then

        for _,v in pairs(array) do
            local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.Position - v.CFrame.Position).magnitude -- v is the value its looping through

            if distance <= 15 then
                print("Test Succesful")

                break -- breaks the loop
            end
        end
    end
end)

generic for loops

Ad

Answer this question