It works perfectly fine, but there is a bunch of lag when the script runs The script is inside a door and is only supposed to run once. It teleports you outside of the building, it sets anchored to false if there is a model inside of the model, it breaks glass, and unanchores everything else.
debounce = false
script.Parent.Touched:connect(function(part)
local h = part.Parent:FindFirstChild("Humanoid")
if h then
local plr = game.Players:GetPlayerFromCharacter(h.Parent)
if plr and debounce == false then
debounce = true
wait()
local clone = game.ServerStorage.ScreenGui:Clone()
clone.Parent = plr.PlayerGui
for i = 1,0,-.1 do
wait()
clone.Frame.BackgroundTransparency = i
end
plr.Character.Torso.CFrame = CFrame.new(155.3, 4.3, -28.1) -- teleporting
wait()
for i = 0,1,.1 do
wait()
clone.Frame.BackgroundTransparency = i
end
wait(1)
local c = workspace.Building1:GetChildren()
for i,v in pairs(c) do
if v.ClassName == "Model" then
local b = v:GetChildren()
for i,_ in pairs(b) do
_.Anchored = false -- unanchores every thing inside the model of the model(building1)
end
elseif v.Size == Vector3.new(10,0.2,10) then --checks if v is glass by checking size of a part
wait()
v.Parent = game.ServerStorage--sets parent
local clone = game.ServerStorage.BGlass3:Clone()
clone:SetPrimaryPartCFrame(v.CFrame)
clone.Parent = workspace
else
v.Anchored = false--unanchores everything else
end
end
end
end
end)
the scripts purpose is supposed to simulate a building being blown up. If you want to see the lag: http://www.roblox.com/games/73660217/Personal-Server

2 comments
Put waits in every path of your for loops, that should fix the problem or at least help it.
@FearMeIAmLag wow your username is perfect