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

Why is CharacterAdded() not working after the user resets?

In my game a function allows users to morph into a model then colour those model parts using this script. It works fine in testing mode and in Online mode, but once players reset the coloring script stops working altogether.

I think it may be the character added function but I don't know how to force it to refresh even after the player resets. Any suggestions?

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
repeat wait() until repeat wait() until player.CharacterAdded:connect(function() loaded = true end)
script.Parent.MouseButton1Click:connect(function()
	local Get = character:GetChildren()
	for i = 1, #Get do
		if Get[i].ClassName == "Model" then
			local Gget = Get[i]:GetChildren()
			for i = 1, #Gget do
				if Gget[i].Name == script.Parent.Parent.Parent.Parent.Target.Value then
				Gget[i].BrickColor = BrickColor.new(script.Parent.Name)
				end
			end
		end
	end
end)

Thankyou very much

1 answer

The problem is that character becomes nil after the player dies, and remains like that even after respawning. To fix this, you could change line 3 to this:

repeat wait() until repeat wait() until player.CharacterAdded:connect(function(char) character = char loaded = true end)

4 comments

0

repeat wait() until twice?

0

But thankyou so much from the entire team we have been trying to fix this for so long =.=

0

Your script does repeat wait() until twice; it's probably not necessary but I included it anyway.

0

Oh Im sorry, I wasnt using this script in game so I hadnt noticed my mistake. Many thanks nonetheless

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