Problem with morph script

Hey i have this script that morphs you into another character from workspace but i have a problem so after you respawn for some reason the player doesnt morph into the character again anyone knows how to fix it

local Players = game:GetService("Players")
local box = workspace
local characterName = "Char"
local morphFinishedEvent = game.ReplicatedStorage:WaitForChild("MorphFinishedEvent")
local ServerStorage = game:GetService("ServerStorage")

Players.PlayerAdded:Connect(function(player)
	local hasMorphed = false

	player.CharacterAdded:Connect(function(character)
		if hasMorphed then return end
		hasMorphed = true

		task.delay(2, function()
			local customChar = box:FindFirstChild(characterName)
			if customChar then
				local charClone = customChar:Clone()
				charClone.Name = player.Name

				local spawnCFrame = character:FindFirstChild("HumanoidRootPart") and character.HumanoidRootPart.CFrame

				charClone.Parent = workspace
				player.Character = charClone

		
				local animateScript = customChar:FindFirstChild("Animate")
				if animateScript then
					animateScript:Clone().Parent = charClone
				end

				-- Clone the SprintScript if it exists
				local sprintScript = customChar:FindFirstChild("sprintScript")
				if sprintScript then
					sprintScript:Clone().Parent = charClone
				end

				local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
				if rootPart and spawnCFrame then
					rootPart.CFrame = spawnCFrame
				end

		
				for i = 1, 4 do
					local powerValue = charClone:FindFirstChild("power" .. i)
					if powerValue and powerValue.Value and powerValue.Value ~= "" then
						local toolName = powerValue.Value
						local tool = ServerStorage.Tools:FindFirstChild(toolName)
						if tool then
							local toolClone = tool:Clone()
							toolClone.Parent = player.Backpack
						end
					end
				end

			
				morphFinishedEvent:FireClient(player)
			end
		end)
	end)
end)

hasMorphed - a local variable - is never set to false after the character is added for the first time, which prevents the function from running again. Where did you try to set this variable, or did you forget to do that?

1 Like

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