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

CharacterAdded is not firing?

I'm trying to make it so your items save to your StarterGear so you'll respawn with the same items you had when you died. The problem is simple. CharacterAdded isn't firing... which obviously means chr.ChildAdded isn't firing either. Why?

function AddTool(plr, obj)
	print(obj:GetFullName())
	if obj:IsA("Tool") or obj:IsA("HopperBin") and not plr.StarterGear[obj.Name] then
		obj:Clone().Parent	= plr.StarterGear
	end
end

game.Players.PlayerAdded:connect(function(plr)
	local bp	= plr:WaitForChild("Backpack")
	bp.ChildAdded:connect(function(obj)
		AddTool(plr, obj)
	end)
	plr.CharacterAdded:connect(function(chr)
		print("CharacterAdded")
		chr.ChildAdded:connect(function(obj)
			print("Child Added")
			AddTool(plr, obj)
		end)
	end)
end)

1 answer

✓ Accepted answer

According to the wiki, the backpack is deleted and replaced with a new version when your character respawns. This means that by the time your script detects the backpack, your character has already respawned so it doesn't fire the CharacterAdded event. Therefore, try changing your code to this so that it always makes sure you have the new backpack after the character gets added:

function AddTool(plr, obj)
    print(obj:GetFullName())
    if obj:IsA("Tool") or obj:IsA("HopperBin") and not plr.StarterGear[obj.Name] then
        obj:Clone().Parent  = plr.StarterGear
    end
end

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        print("CharacterAdded")
local bp = plr:WaitForChild("Backpack")
    bp.ChildAdded:connect(function(obj)
        AddTool(plr, obj)
    end)
        chr.ChildAdded:connect(function(obj)
            print("Child Added")
            AddTool(plr, obj)
        end)
    end)
end)

Note: I'm on an iPad so I'm not perfectly sure if it works. This is just what I observed wrong with your code.

3 comments

1

Same. I hate IPads. We want keyboards! Give us a Mac!

0

Thank you so much! Also, can you link to where the wiki says that for future reference?

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