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

Why is this super laggy? Is there something in this script?

Asked by 10 years ago

This is the script for my game, When I try to test it out it lags like crazy. I used Fraps and it said I had 0 FPS. Is there something in the script making it lag and is there something I could do to prevent it?

game.Players.PlayerAdded:connect(function(newplyr)
    local lb = Instance.new("IntValue", newplyr)
    local Wins = Instance.new("IntValue")
    script.Players.Value = script.Players.Value+1
    Wins.Parent = lb
end)

game.Players.PlayerRemoving:connect(function(newplyr)
    script.Players.Value = script.Players.Value-1
end)

while true do
    local rr = math.random(1,1)
    if script.Players.Value >= 2 then--Players needed
if rr == 1 then
    target = CFrame.new(0, 3, 0)
for i, player in ipairs(game.Players:GetChildren()) do
   if player.Character and player.Character:FindFirstChild("Torso") then
      player.Character.Torso.CFrame = target + Vector3.new(0, 0, 0)
   end
end
game.Lighting.Safe:clone().Parent = workspace
local h = Instance.new("Hint", workspace)
h.Text = "Spread Out!"
wait(3)
Time = 5
repeat
Time = Time-1
h.Text = "Time left to spread out: "..Time..""
wait(1)
until Time <= 0
h:remove()
workspace.Safe:remove()
game.Lighting.Spleef_Arena:clone().Parent = workspace
Time = 60
repeat
    Time = Time-1
    h.Text = "Time left: "..Time..""
    wait(1)
until Time <= 0
h.Text = "Time's up!"
game.Workspace.Spleef_Arena:remove()
wait(4)
h:remove()
end
    else
    local h = Instance.new("Hint", workspace)
    plyrs = 2-script.Players.Value
    if plyrs == 1 then
    h.Text = "You need "..plyrs.." more player!"
    else
        h.Text = "You need "..plyrs.." more players!"   
    end
end
end
1
Correct me if I'm wrong, but it appears that the loop on line 12 lacks a proper wait. IcyArticunoX 355 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

I think IcyArticuno is right. It's executing all that code so fast that your game is lagging big time

0
What could I do? EzraNehemiah_TF2 3552 — 10y
0
Replace "while true do" with "while wait() do". wait(0.2) --Waits 1 fifth of a second dudemanloserr 15 — 10y
Ad

Answer this question