Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to make this less laggy?

Asked by 9 years ago

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

0
Put waits in every path of your for loops, that should fix the problem or at least help it. FearMeIAmLag 1161 — 9y
0
@FearMeIAmLag wow your username is perfect Senor_Chung 210 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Yes, probably.. So what i'm thinking is your wait's are to small so, double the wait time.

wait(5)
...
...
...
wait(5)
...
...
...
-- Coding..
0
Oh and another thing, it's going to be laggy due to the fact it's loading Roblox's core scripts and unachoring them all at one time. Roblox_v10 33 — 9y
Ad

Answer this question