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

What is wrong with my function?

Asked by 8 years ago

Every time I run through my code the function does not continue passed the first if statement. Even when players has values it still won't continue. I have even tried changing

players

to

players[1]

Here's the code:

playersService = game:GetService("Players")
ServerScript = game:GetService("ServerScriptService")

function testPlayerDeath()
    local players = playersService:GetChildren()
    if players == not nil then
        print("if done")
            for _, players in pairs(players) do
                script.ChildAdded:connect(function()
                    print("passed")
                    if script:FindFirstChild(players.Name) == players.Name then 
                        print("passed2")
                        local Value = script:WaitForChild(players)
                        if Value.Value == true then
                            print("passed3")
                            print("Current Selection: "..players)
                            onPlayerDeath(players)
                            failed = false
                            return failed
                        else
                            failed = true
                            return failed
                        end
                    end
                end)
            end
    else
        failed = true
        return failed
    end
end


while true do
    wait()
    testPlayerDeath()
    print("failed?: ")
    print(failed)
end

if you find anything confusing or wrong in my code please leave a comment.

edit: the use of the return is simply for debugging

0
Your code connects the script.ChildAdded event infinitely. Take that part out of the function. Also, why aren't you using the Died function of humanoid? It'll also get hung on line 13, especially as a table can't be a child. GoldenPhysics 474 — 8y

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Even when corrected, the first if statement has no purpose being there. Checking if a player exists, even though you're referencing it directly from the PlayerService, is useless.

Ad

Answer this question