No it wouldnt work. It will cause errors and coroutine is improperly used. I know it can cause performance issues, but youre just gonna have to use a tick function with GetPartsInPart.
here. this only changes values when it detects a change or a missing player.
local AllPlayersInside = {}
function RecurssiveParent(Obj)
local player =game.Players:GetPlayerFromCharacter(Obj)
if player then
return Obj
elseif Obj.Parent ==workspace then
return false
else
return RecurssiveParent(Obj.Parent)
end
end
while true do
wait(.1)
local AllTouchingParts = workspace:GetPartsInPart(script.Parent)
local Flag=false
for __,element in pairs(AllPlayersInside)do
element.Value=false
end
for __,element in pairs(AllTouchingParts) do
local PlayerObj=RecurssiveParent(element)
if PlayerObj then
if AllPlayersInside[PlayerObj.Name]==nil then
local Player = game:GetService("Players"):GetPlayerFromCharacter(PlayerObj)
Player:WaitForChild("Indoor").Value=true
AllPlayersInside[PlayerObj.Name] = {Player=Player,Value=true}
else
AllPlayersInside[PlayerObj.Name].Value=true
end
end
end
for index,element in pairs(AllPlayersInside) do
if not element.Value then
element.Player:WaitForChild("Indoor").Value=false
AllPlayersInside[index]=nil
end
end
end