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

How would I find an object with the same name as a player?

I am making something for when a player dies this boolvalue changes to true, it won't work though

function onHumanoidDied(humanoid, player)
 for _, playerdead in pairs (game.Workspace.PlayerStuffs:FindFirstChild(player.Name)) do
	playerdead.Value = true
 end
end

Thats the code.

1 answer

FindFirstChild does not return a table, it returns the first object found matching the string you give it.

Therefore, your loop will not actually run because there is no table for it to iterate through!

You should also just get rid of the humanoid parameter in your function; you never actually end up having to use it.

You should revise your function to...

function onHumanoidDied(player)
	local playerDead = workspace.PlayerStuffs:FindFirstChild(player.Name)
	if playerDead and playerDead:IsA("BoolValue") then 
		-- check if the object exists and is a boolvalue
		-- if it is, set the object's value to true
		playerDead.Value = true
	end
end

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