Some issues with my Morph System Script

What is the issue?

I recently made a “Morph Script” and i’m using the same “Custom Character” for all the characters in-game, I also have a custom “Animate” script inside “StarterCharacterScripts” that has all the animations for those “Custom Characters”…

When i test the game in Roblox website (Not studio) with a friend, we have an issue with animations… At first we both can see our animations but when we use the “Morph System” animations won’t play on other players and they will stay in “T Pose” forever…

We also have another issue that when the players resets, they won’t keep the character they had before resetting…

Video with the issue

What solutions have you tried so far?

I tried to search for solutions on Youtube, Developer Hub, Google… and i found nothing that could help me fix these issues…

Script

local changeEvent = game.ReplicatedStorage.Events:WaitForChild("ChangePlayerCharacter")

local charsFolder = game.ReplicatedStorage:WaitForChild("Servants")

changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
	if charsFolder:FindFirstChild(chosenCharacter) then
		local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
		local plrChar = player.Character
		
		if newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.HumanoidRootPart
			newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
		elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.Torso
			newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
		end
		
		if player.Character:FindFirstChild("Animate") then
			local anim = player.Character:FindFirstChild("Animate"):Clone()
			anim.Parent = newChar
		end
		
		newChar.Name = player.Name
		player.Character = newChar

		local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
		local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		newChar.Parent = workspace
	else
		warn("Character doesn't exist or something went wrong, Try again.")
	end
end)

Hope that someone could help us… Thanks in advance!

1 Like

sorry for going off of the main topic of this post, but you should really add a ratelimit to this, it can be spammed with an exploit to crash the server

But they can’t access server scripts, right? If so, how could i add a ratelimit? I’m still learning scripting xD

No. Exploiters cannot access and edit server sided content. As for the rate limit I’m only assuming he means a Debounce. If that’s the case just add something like this

local DB = false

if DB == false then
     DB = true
     --Code
     Task.wait(3) --edit to how long you want to wait between calls
     DB = false
end

Hope that helps!

As for the actual issue I unfortunately don’t know much about morphs and am unsure of how to help you. Sorry.

above script would slow down your game

local ratelimits = {}
changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
 if not ratelimits[player] then
        ratelimits[player] = 0
    end
    if tick() - ratelimits[player] < 2 then -- if it has been less than 2 seconds since the last spawn p much
        return
    end
    ratelimits[player] = tick()
    if charsFolder:FindFirstChild(chosenCharacter) then
    --rest of the script here
1 Like

Oh i see, will try that so i can secure servers a bit more, Thanks!

And let’s hope that someone can help with the main topic issue of this post!

animations won’t play on other players and they will stay in “T Pose” forever…<<<

by the video, I would say the animate script was not in the new morph although the script is calling for it, seems like it could be a yielding issue. My first step would be to run the experience, recreate the bug and in the explorer, find the character and make sure the animate file is there. Also, look for duplicates while there.

If this is the case, the easiest fix is to add the animate script into the morph you are giving.

1 Like

Just a quick question… How do i add the “Animate” script to the morph? Like putting the script inside the “Morph character” model?

yeh, the script you provided pretty much moves you to the new character and you inherit everything inside that char. Although, its odd cuz the script also calls for the animate script to be cloned from your original char so it requires you to check what else could be causing this.

I hope this helps :slight_smile: