The code detects that if you’re at reach of a wall, you’ll be able to hide in a grass wall, so it goes through a process, hides in the wall, and then does a loop that makes the character invisible and non-Collidable, but then after a cooldown I want it to bring them back to their past original state, but the first loop doesn’t allow the next lines to run.
As you can see it does enter the wall, makes them invisible, but then it doesn’t bring them back to the original position and turns the parts visible. (Cooldown is set to 2)
If you need more information please ask right away, thank you so much!
if onReach then
-- Hide in Wall --
print("passing")
local oldPos = rootPart.CFrame
rootPart.Anchored = true
rootPart.CFrame = CFrame.new(action,rootPart.Position) + Vector3.new(1.5 * rootPart.CFrame.LookVector.X,0,1.5 * char.HumanoidRootPart.CFrame.LookVector.Z)
char.Humanoid.AutoRotate = false
for i, parts in pairs(char:GetChildren()) do
if parts.ClassName ~= "Part" then return end
PhysicsService:SetPartCollisionGroup(parts, "Hidden")
parts.Transparency = 1
end
print("running")
wait(hiddenDuration)
rootPart.Anchored = false
rootPart.CFrame = oldPos
char.Humanoid.AutoRotate = true
for i, items in pairs(char:GetChildren()) do
if items.ClassName ~= "Part" then return end
PhysicsService:SetPartCollisionGroup(items, "Default")
items.Transparency = 0
end
end