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
6 years ago

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

1local m = game.Workspace.E
2yes = {m.Circle,m.hallleave}
3local UIS = game:GetService("UserInputService")
4 
5UIS.InputBegan:Connect(function(Key)
6    if Key.KeyCode == Enum.KeyCode.E and (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - yes.Position).magnitude <= 15 then
7        print("Test Succesful")
8    end
9end)
1
?????? Amiaa16 3227 — 6y
0
what User#23365 30 — 6y
0
o i get it User#23365 30 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 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.

01local thing = game.Workspace.E
02local array = {m.Circle, m.hallleave}
03local UIS = game:GetService("UserInputService")
04 
05UIS.InputBegan:Connect(function(key)
06    if key.KeyCode = Enum.KeyCode.E then
07 
08        for _,v in pairs(array) do
09            local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.Position - v.CFrame.Position).magnitude -- v is the value its looping through
10 
11            if distance <= 15 then
12                print("Test Succesful")
13 
14                break -- breaks the loop
15            end
16        end
17    end
18end)

generic for loops

Ad

Answer this question