All local scripts stop working after Players character is changed

  1. What do you want to achieve?
    I’m attempting to change the Players character.

  2. What is the issue?
    Whenever the character gets changed any local script inside of ‘StarterPlayerScripts’ stop working. I also get the same issue if the player dies or resets.

  3. What solutions have you tried so far?
    I have tried making it so the local scripts will reset once the player respawns but they then don’t detect any UI getting clicked. I also tried multiple different solutions across multiple forums including here and yet nothing worked.

The only solution I can think of that may work would be moving everything into ‘StarterGui’ since it would reset upon spawn, but It would mean I’d have to rewrite all the code to work inside of it. So before I do that is there anyway to make it so they can stay inside ‘StarterPlayerScripts’?

just in case it’s needed here is the code that changes the Players character:

local Model = script.Parent
local Prompt = Model.Part.ProximityPrompt

	local OldChar = Plr.Character
	local NewChar = Model.StarterCharacter:Clone()
	NewChar.HumanoidRootPart.Anchored = false
	NewChar.HumanoidRootPart.CFrame = OldChar:WaitForChild("HumanoidRootPart").CFrame
	Plr.Character = NewChar
	NewChar.Parent = workspace

–Sorry if I did something wrong, I’ve never posted here before.

1 Like

I found no solution to this other then using CharacterAdded and PlayerAdded to make scripts run after Player death.

If you are having the same issue I’d recommend going through the effort of moving all UI related scripts into PlayerGui as it saves a whole load of time and makes scripts reset upon death. You could also move them into PlayerCharacter except I wouldn’t recommend it as they would not be very secure due to the scripts then being stored on the Players character.

If you are interested I later figured out the reason they would break was because the Gui would reset upon death but not the scripts stored inside StarterPlayerScripts so any varibles inside those scripts would still be tied to the old Character and Gui.

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