Player.CharacterAdded not firing when character respawns

Hi, I am working on a custom admin script and want a script to be parented to the character every time it respawns. It only works when the player joins the game, but not when you respawn.

This is in a separate script

local function cloneStuff(plr)
	local char = plr.Character
	
	if not char:FindFirstChild('SyAdHandler') then
		local handler = script:WaitForChild('SyAdHandler'):Clone()
		handler.Parent = char
		handler.Disabled = false
	end
	
	if not plr.PlayerGui:FindFirstChild('SnowAdminClient') then
		local clientScript = script.Parent:WaitForChild('SnowAdminClient'):Clone()
		clientScript.Parent = plr.PlayerGui
		clientScript.Disabled = false
	end
	
	if not plr.PlayerGui:FindFirstChild('CameraInfo') then
		local ccInfo = script.Parent:WaitForChild('CameraInfo'):Clone()
		ccInfo.Parent = plr.PlayerGui
		ccInfo.Disabled = true
	end
	
	if not plr.PlayerGui:FindFirstChild('CmdBar') then
		local cmdBar = script.Parent:WaitForChild('Assets'):WaitForChild('CmdBar'):Clone()
		cmdBar.Parent = plr.PlayerGui
		cmdBar.Enabled = true
	end
	
	local isFlying = Instance.new('BoolValue', char)
	isFlying.Name = 'isFlying'
	isFlying.Value = false
end

game.Players.PlayerAdded:Connect(function(plr)
		for i = 1, #config.rankNumbers do
			if config.ranks[config.rankNumbers[i]] then
				local rank = config.ranks[config.rankNumbers[i]]

				if table.find(rank, plr.Name) or table.find(config.rankedPlayers, plr.UserId) then
					plr.CharacterAdded:Connect(function(char)
						task.wait()
						
						cloneStuff(plr)

						local ccInfo = plr.PlayerGui:WaitForChild('CameraInfo')

						local handler = char:WaitForChild('SyAdHandler')

						handler:SetAttribute('Rank', i)

						if char:FindFirstChild('isFlying') then

							char:FindFirstChild('isFlying'):GetPropertyChangedSignal('Value'):Connect(function()
								if char:FindFirstChild('isFlying').Value == true then
									ccInfo.Disabled = false
								else
									ccInfo.Disabled = true
								end
							end)
						end
					end)
				end
			end
		end
	end)

I tried to look up a solution on dev forum plus the wiki, but can’t seem to find a fix.

2 Likes

Im pretty sure its because its inside the PlayerAdded function and is part of an if statement. Try moving the CharacterAdded fucntion outside of other functions and temporally placing it in the main script to see if that works.

nope,
both playeradded and characteradded are events,
and not part of an if statement…

Nothing changed, same thing happened.

how about you put a print set in each part of the script to see if you know where the error is

I’ve done this already, the problem is that it prints when the player joins the game, but when the character respawns, it doesn’t print anything.

Maybe switch these two lines with one another
image

plr.CharacterAdded:Connect(function(char)
    if table.find(rank, plr.Name) or table.find(config.rankedPlayers, plr.UserId) then
    
    end
end)

Once again, nothing changed and still doesn’t work.

Figured it out myself, but thanks for trying to help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.