I'm trying to make a door, basic stuff. As i did i encountered that the conditions that i gave the 'for loops' aren't right but i don't understand, may somebody say why?
local range = 20
local sensor = script.Parent
local open = false
-- -38.5, 3.2, 151.7
-- to
-- -33.3, 3.2, 151.7
--[[
for _, spottedPlayer in pairs(allPlayers) do
if spottedPlayer ~= player then
print(spottedPlayer.Name)
local selfPos = char.HumanoidRootPart.Position
local localPlayerPos = spottedPlayer.Character.HumanoidRootPart.Position
if (localPlayerPos - selfPos).magnitude < range then
]]--
local moveDoor = function(state)
if state == "open" then
for i = sensor.Position.X, -33.3, -0.1 do
print(i)
sensor.Position = Vector3.new(i, sensor.Position.Y, sensor.Position.Z)
print("Opening")
wait(0.2)
end
else
for i = sensor.Position.X, -38.5, 0.1 do
sensor.Position = Vector3.new(i, sensor.Position.Y, sensor.Position.Z)
wait(0.2)
end
end
end
local standby = function()
local allPlayers = game.Players:GetPlayers()
for i = 1, #allPlayers do
local playerPos = game.Workspace:FindFirstChild(allPlayers[i].Name).HumanoidRootPart
if (sensor.Position - playerPos.Position).magnitude < range and not open then
print("Open")
moveDoor("open")
wait(6)
moveDoor("nope")
end
end
end
connection = game.Players.PlayerAdded:connect(function(Player)
connection:disconnect()
wait(5)
while true do
standby()
wait()
end
end)

7 comments
You aren't calling the function.
I do, somewhere else in the script. but when is called the 'fors' are skipped.
Any errors? Also, where do you call the function?
No, it runs nicely. But the 'for' loops are skipped
We'll need more code to solve this
Alright
Theres the whole code