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

How to transfer movements Animate script when changing player's character?

Hey, I've done a simple ModuleScript with a function that should morph players to a new character, and transfer over the body colors and the animations. I'm having a problem, that when I copy the "Animate" localscript located in a player's character model to another model, it doesn't work. There are no animations. In an older project, this appears to work when done client-side (localscript). Why is it not working, and if it works only under localhost, how'd I make it visible to all players?

Code below (lines 52-61 of interest)

local module = {}


local animateScriptDefault = script:WaitForChild("Animate")
local cameraFixEvent = script:WaitForChild("CameraFixEvent")
local function errorLog(message, player)
	print("["..script.Name.."] Error morphing player '"..player.Name.."': "..message)
end
local function warningLog(message)
	print("["..script.Name.."] Warning: "..message)
end
local function infoLog(message)
	print("["..script.Name.."] "..message)
end


function module.Morph(player, model)
	-- Make sure all parameters are of correct type
	if player == nil or not player:IsA("Player") then
		errorLog("Parameter 'player' isn't a valid Player!", player)
		return
	end
	if module == nil or not model:IsA("Model") then
		errorLog("Parameter 'model' isn't a valid Model!", player)
		return
	end
	
	-- Initialize variables and make sure they are all valid
	local orig = player.Character;
	if orig == nil then
		errorLog("Character not found. Is it loaded yet?", player)
		return
	end
	
	local morph = model:Clone()
	if morph == nil then
		errorLog("Failed to clone model '"..model.Name.."', make sure it is archivable!")
		return
	end
	morph.Parent = game.Workspace
	morph.Name = player.Name
	morph:SetPrimaryPartCFrame(orig:GetPrimaryPartCFrame())

	-- Copy over skin colors and movement animations script
	local skinColors = orig:FindFirstChild("Body Colors")
	if skinColors == nil or not skinColors:IsA("BodyColors") then
		warningLog("Player '"..player.Name.."' does not contain valid Body Colors - the resulting morph may be completely gray.")
		return
	end
	skinColors.Parent = morph
	
	local animateScript = orig:FindFirstChild("Animate"):Clone()
	if animateScript == nil or not animateScript:IsA("LocalScript") then
		warningLog("Player '"..player.Name.."' does not contain a valid Animate script - using morph's script or defaults.")
		animateScript = morph:FindFirstChild("Animate") -- Try to get the script from the destination morph
		if animateScript == nil or not animateScript:IsA("LocalScript") then -- Or clone the default one if not present
			animateScript = animateScriptDefault:Clone()
			if animateScript == nil then return errorLog("Fatal: Failed to clone default movement animation script - try redownloading the script pack.") end			
		end
	end
	animateScript.Parent = morph
	
	-- Replace the character
	player.Character = morph
	orig:Destroy()
	
	-- Fix camera
	cameraFixEvent:FireClient(player, morph)
	
	infoLog("Successfully morphed player '"..player.Name.."' into '"..model.Name.."'")	
end
infoLog("Initialized!")
return module

**Note: **This module is required and called upon server-side, meaning from a Script.

1 answer

i dont feel like reading through all that but im sure you missed that you need to set the player character to the morph for the local script "animate" to actually work with the morph

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