Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Using a table with a if function?

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)

3 comments

1

??????

0

what

0

o i get it

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.