Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is wrong with my function?

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

1 comment

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.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.