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

This script freezes my game and I don't know why. Please help?

Asked by 6 years ago
Edited 6 years ago

The script (posted below) will freeze the server and I don't see why. This code is part of my Build Battle game, so after it is resolved I will censor it, but only because I don't want people stealing my game.

function doSpecialRound(buildTime, voteTime, intermissionTime)
    throw("notification","This round will be different!")
    wait(11)
    throw("notification","This round you will have to guess what the player is building")   
    setStatus("Choosing builder...")
    wait(3)
    player = get_Child(game.Players,math.random(0,#game.Players:GetChildren()))
    if player.Character and player.Character.HumanoidRootPart then
        player.Character:MoveTo(workspace.Teleports.LobbyBase.base.Position)
    end
    -- Give tools
    for i,v in pairs(game.ServerStorage.StamperTools:GetChildren()) do
        tool = v:Clone()
        tool.Parent = player.Backpack
    end
    ncs = script.Resources.NoChatScript:Clone()
    ncs.Parent = player.Backpack
    ncs.Disabled = false
    workspace.MakeChat:FireAllClients("The bonus round has started! Chat what you think the builder is making!")
    i = 90
    category = tostring(cat[ch])
    for i,v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.main.Frame.Category.Text = "Mystery"
    end
    player.PlayerGui.main.Frame.Category.Text = category
    -- Chat hook
    setStatus("Mystery round...")
    for i,v in pairs(game.Players:GetChildren()) do
        pcall(function()
        v.Chatted:connect(function(msg)
            if string.lower(msg) == string.lower(category) then
                throw("msg",v.Name .. " has guessed the theme!")
                workspace.MakeChat("The theme was " .. category)
                game.PointsService:AwardPoints(v.UserId,100)
                v.leaderstats.Wins.Value = v.leaderstats.Wins.Value+1
                for i,v in pairs(game.Players:GetChildren()) do
                pcall(function()
                v.Chatted:disconnect() -- Deprecated, but options are limited
                end)
                end
            end
        end)
        end)
    end
    while i > -1 do
        for i,v in pairs(game.Players:GetChildren()) do
            pcall(function()
            v.PlayerGui.main.Frame.Time = i
            i=i-1
            wait(1)
            end)
        end
    end
end

EDIT (1):

local get_Child=function(obj,index)
    return obj:children()[tonumber(index)]
end
0
Beyond me, I would help... if I could AlphaGamer150 101 — 6y
0
Ok thanks for the quick reply though SebbyTheGODKid 198 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

Pretty sure its got to do with the while loop on line 45, no idea what you are trying to do in this loop but its wrong.

For instance, you use i as your timer number but also reuse it in a for loop on line 47 (for i,v) so the timer version of i never gets subtracted from because you only subtract within this loop. Rename one of the i's.

Also line 38, :disconnect is deprecated but :Disconnect() isn't so if you wanna change that.

0
ah, i thought Disconnect() and disconnec() were the same, thanks for the clarification. And also thanks for the help! SebbyTheGODKid 198 — 6y
0
Did the help fix your issue or are you still having trouble? 128Gigabytes 20 — 6y
0
no, sorry. the freeze still occurs SebbyTheGODKid 198 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Alright, so the problem still occurs, and here is the revised code:

function doSpecialRound(buildTime, voteTime, intermissionTime)
    throw("notification","This round will be different!")
    wait(11)
    throw("notification","This round you will have to guess what the player is building")   
    setStatus("Choosing builder...")
    wait(3)
    player = get_Child(game.Players,math.random(0,#game.Players:GetChildren()))
    if player.Character and player.Character.HumanoidRootPart then
        player.Character:MoveTo(workspace.Teleports.LobbyBase.base.Position)
    end
    -- Give tools
    for i,v in pairs(game.ServerStorage.StamperTools:GetChildren()) do
        tool = v:Clone()
        tool.Parent = player.Backpack
    end
    ncs = script.Resources.NoChatScript:Clone()
    ncs.Parent = player.Backpack
    ncs.Disabled = false
    workspace.MakeChat:FireAllClients("The bonus round has started! Chat what you think the builder is making!")
    timer = 90
    category = tostring(cat[ch])
    for i,v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.main.Frame.Category.Text = "Mystery"
    end
    player.PlayerGui.main.Frame.Category.Text = category
    -- Chat hook
    setStatus("Mystery round...")
    for i,v in pairs(game.Players:GetChildren()) do
        pcall(function()
        v.Chatted:connect(function(msg)
            if string.lower(msg) == string.lower(category) then
                throw("msg",v.Name .. " has guessed the theme!")
                workspace.MakeChat("The theme was " .. category)
                game.PointsService:AwardPoints(v.UserId,100)
                v.leaderstats.Wins.Value = v.leaderstats.Wins.Value+1
                for i,v in pairs(game.Players:GetChildren()) do
                pcall(function()
                v.Chatted:disconnect() -- Deprecated, but options are limited
                end)
                end
            end
        end)
        end)
    end
    while timer > -1 do
        for _,v in pairs(game.Players:GetChildren()) do
            pcall(function()
            v.PlayerGui.main.Frame.Time = timer
            timer=timer-1
            wait(1)
            end)
        end
    end
end
0
Is it possible your pcall is failing at line 48 causing line 49 and 50 to not run, so it is a endless loop with no waits? Put the wait and timer subtraction outside the pcall and see what happens. 128Gigabytes 20 — 6y
0
ok, smart idea SebbyTheGODKid 198 — 6y
0
Edit the question + comment on previous answer rather than posting another answer plz :) Goulstem 8144 — 6y
0
Ok the problem is solved! Thanks for all your help. You can see the script in-action on my Build Battle game. (1158750748) SebbyTheGODKid 198 — 6y

Answer this question