Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
0
repeat wait() until twice? Samstergizmo 28 — 7y
0
But thankyou so much from the entire team we have been trying to fix this for so long =.= Samstergizmo 28 — 7y
0
Your script does repeat wait() until twice; it's probably not necessary but I included it anyway. IDidMakeThat 1135 — 7y
0
Oh Im sorry, I wasnt using this script in game so I hadnt noticed my mistake. Many thanks nonetheless Samstergizmo 28 — 7y
Ad

Answer this question