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

Infinite yield possible on 'ReplicatedStorage:WaitForChild("StatusTag")' ?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a MM2 style game, and for my MainScript I'm getting an error when testing. 17:51:43.741 - Infinite yield possible on 'ReplicatedStorage:WaitForChild("RemoteEvent")' and 17:51:43.768 - Infinite yield possible on 'ReplicatedStorage:WaitForChild("StatusTag")' I do not understand what this means or how to fix it... heres the entire script.

--Made by Deddlox and ExplodingNightWolf



--times
local roundtime = 60 * 5
local intermissiontime = 20

--defining
local serverstorage = game:GetService("ServerStorage")
local replicatedstorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local event = replicatedstorage:WaitForChild("RemoteEvent") 
local maps = serverstorage:WaitForChild("Maps")
local mapholder = game.Workspace:WaitForChild("MapHolder")
local statustag = replicatedstorage:WaitForChild("StatusTag")
local timertag = replicatedstorage:WaitForChild("TimerTag")



--leaderboard/awarding points
function awardpoints (player, points)
    if player and points then 
        local leaderstats = player.FindFirstChild("leaderstats")
        if leaderstats then
            local pointsvalue = leaderstats:FindFirstChild("Points")
            if pointsvalue then
                pointsvalue.Value = pointsvalue.Value + points
            end
        end
    end
end


--net gun for when the detective dies, someone else can pick it up ( do not have to use if. )
function dropnetgun(pos)
    local pickup = serverstorage:WaitForChild("Net Gun"):WaitForChild("Handle"):clone()
    pickup.Name = "Pickup"
    pickup.Anchore = true
    pickup.CanCollide = false
    pickup.CFrame = CFrame.new(pos)
    --what the net gun looks like when on ground, hovering
    local sparkles = Instance.new("Sparkles")
    sparkles.SparkleColor = Color3.new(0, .5, 1)
    sparkles.Parent = pickup
    --clones the net gun so it respawns and doesn't disapear each round
    local given = false
    pickup.Touched:connect(function(hit)
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid and humanoid.Health > 0 then
            local player = game.Players:GetPlayFromCharacter(hit.Parent)
            if player and player ~= slasher then
                local backpack = player:FindFirstChild("Backpack")
                if backpack and not given then
                    given = true
                    pickup:remove()
                    local netgun = serverstorage:WaitForChild("Net Gun"):clone()
                    netgun.Parent = backpack
                    detective = player
                end
            end
        end
    end)
    --walkspeed/ etc for detective handling the net gun
    for _, player in pairs (game.Players:GetChildren()) do
        if player and player.Character and player.Character.Parent then
            local humanoid = player.Character:FindFirstChild("Humanoid")
            if humanoid and humanoid.WalkSpeed < 16 then
                humanoid.WalkSpeed = 16
            end
        end
    end

    debris:AddItem(pickup,roundtime)
    pickup.Parent=game.Workspace
end

-- can change slashedplayer etc.
--tools
function newcharacter(slashedplayer, character)
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid then
        humanoid.Died:connect(function()
            end)
            if slashedplayer == detective then
                humanoid:UnequipTools()
                local backpack = slashedplayer:FindFirstChild("Backpack")
                if backpack then
                    backpack:ClearAllChildren()
                end
            local torso =character:FindFirstChild("Torso")
            if torso then
                dropnetgun (torso.Position)
            end


            local tag = humanoid:FindFirstChild("Creator")
            if tag and tag.Value and tag.Value.Parent == game.Players then
            if tag.Value ~= slasher and slashedplayer ~= slasher then
                local wrongdoer = tag.Value
                if wrongdoer.Character and wrongdoer.Character.Parent then
                    local wrongdoerhumanoid = wrongdoer.Character:FindFirstChild("Humanoid")
                    if wrongdoerhumanoid then
                        wrongdoerhumanoid.Health = 0
                    end
                end
            end
            end
        end

    end
end
--leaderstats
function playeradded(player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Parent = leaderstats

    leaderstats.Parent = player

    player.CharacterAdded:connect(function(character)
        newcharacter(player, character)
    end)
    if player.Character and player.Character.Parent then 
        newcharacter(player, player.character)
    end
end
game.Players.PlayerAdded:connect(playeradded)
for _, player in pairs(game.Players:GetPlayers()) do
    playeradded(player)
end


--loading in the map and bringing players to it.
while true do
    statustag.Value = "Loading Map"
    timertag.Value = -1
    mapholder:ClearAllChildren()
    wait(2)
    local allmaps = maps:GetChildren()
    local newmap = allmaps[math.random(1, #allmaps)]
    newmap.Parent = game.Workspace
    wait(2)


    while true do 
        wait (5)
        contestants = {}
        for _, player in pairs(game.Players:GetPlayers()) do
            if player and player.Character then
                local humanoid = player.Character:WaitForChild("Humanoid")
                if humanoid and humanoid.Health > 0 then
                    table.insert(contestants, player)
                end
            end
        end
        -- how much players needed to play
        if #contestants >= 3 then
            break
        else
            --waits for players
            statustag.Value = "Waiting for Players"
            timertag.Value = -1
        end
    end


    --when the match starts
    statustag.Value = "Match"
    timertag.Value = roundtime


    slasher = contestants[math.random(1, #contestants)]

    --chooses whos who ( will need to remove or change up cause involves gui
    while true do
        randomplayer = contestants[math.random(1, #contestants)]
        if randomplayer ~= slasher then
            detective = randomplayer
            break
        end
    end

--telport contestants/players ro game and spawns them in the map properly, and when ends, teleports back to lobby
local spawnsmodel = newmap:WaitForChild("Spawns")   
local spawns = spawnsmodel:GetChildren()
for _, player in pairs (contestants) do
    if player and player.Character and #spawns > 0 then
        local torso = player.Character:WaitForChild("Humanoid")
        local humanoid =  player.Character:WaitForChild ()
        local spawnindex = math.random(1, #spawns) 
        local spawn = spawns[spawnindex]
        if spawn and torso and humanoid then
            humanoid.Health = 100
            humanoid.WalkSpeed = 16
            table.remove(spawns, spawnindex)
            torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))

            local matchtag = Instance.new("StringValue")
            matchtag.Name = "MatchTag"
            matchtag.Parent = player.Character
            --part of gui, may need to remove or change cause this is what gives the player the information of what they are
            local backpack = player:FindFirstChild("Backpack")
            if backpack then
                if player == bloxxer then 
                     local sword = serverstorage:WaitForChild("Sword"):clone()
                     sword.Parent = backpack
                elseif player == detective then
                    event:FireAllClients("Class", "Slasher")
                    local netgun = serverstorage:WaitForChild("NetGun"):clone()
                    netgun.Parent = backpack
                    event:FireAllClients("Class", "Detective")
                else
                    event:FireAllClients("Class", "Citizen")
                    end
                end
            end
        end
    end
    spawnsmodel:remove()
--above last line removes the person's role for that round, and clones it so it chooses a different one next round



--timer and a little bit of gui working
    local localtimer = roundtime
    while localtimer > 0 do
        wait(1)
        localtimer = localtimer - 1
        timertag.Value = localtimer

        activecontestants = {}
        slasheractive = false
        for _, players in pairs (contestants) do
            if player then
                local character = player.Character
                if character then
                    local matchtag = character:FindFirstChild("MatchTag")   
                    local humanoid = character:FindFirstChild("Humanoid")
                    if matchtag and humanoid and humanoid.Health > 0 then
                        if player == slasher then
                            slasheractive = true
                        end
                        table.insert(activecontestants, player)
                    end
                end
            end
        end
        if #activecontestants <=1 or not slasheractive then
            break
        end
    end


--game results
--slasher captured
--if the slasher won and is successful
--sorting the game results
    local gameresult = "PlayersWin"
    if slasheractive then
        if #contestants > 2 then
            --slasher failed
            event:FireAllClients("Result", "PlayersWin")
        else
            --slasher is successful
            gameresult = "SlasherWin"
            event:FireAllClients("Result", "SlasherWin")
        end
    else
        --slasher captured  
        event:FireAllClients("Result", "PlayersWin")
    end
    for _, v in pairs(game.Workspace:GetChildren()) do
        if v then
                if v.Name == "Pickup" or v.className == "Hat" then
                    v:remove()
                end
            end
        end
    end
    for _, player in pairs(contestants) do
        if player then 
            if gameresult == "SlasherWin" and player == slasher then
                awardpoints (player, 9)
            elseif gameresult ~= "SlasherWin" and player ~= slasher then
                if player == detective then
                    awardpoints(player, 4)
                else
                    awardpoints(player, 2)
                end
            end
        end
    end


--teleports players to the lobby
    local lobbyspawns = {}
    for _, v in pairs(game.Workspace:WaitForChild("Lobby"):GetChildren()) do
        if v and v.Name == "SpawnLocation" then
            table.insert(lobbyspawns, v)
        end
    end
    for _, player in pairs(activecontestants) do
        if player then
            awardpoints (player, 1)
            if player.Character then
                local humanoid = player.Character:FindFirstChild("Humanoid")
                if humanoid then
                    humanoid:UnequipTools()
                end
            end

            local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
            player.Character:MoveTo(randomspawn.Position)
            local backpack = player:FindFirstChild("Backpack")

            if backpack then
                backpack:ClearAllChildren()
            end
        end
    end

    --intermission wait
    statustag.Value = "Intermission"
    timertag.Value = intermissiontime
    local localtimer = intermissiontime
    while localtimer > 0 do
        wait(1)
        localtimer = localtimer - 1
        timertag.Value = localtimer
        end





0
We need your script to understand. Ap_inity 112 — 5y
0
If you don't understand that simple error obviously you did not help write this code.. awesomeipod 607 — 5y
0
It's not that simple to me, I've scripted for 1 year and never ever came across it. Deddlox 0 — 5y

Answer this question