How would you create an Unmorph Button/Feature

So I have a morphing system in my game and a popular requested feature is an unmorph button so players can go back to being their avatar without having to reset and go back to spawn. I have looked through multiple dev forum posts and wasn’t able to find anything on something like it.

So how would you go about making it so a player would return to being their avatar after you pressed a button gui?

you could remove the morph from their character with a separate function in the button if thats what u want

You’d want to save their position and reload their character. Link this to a button’s MouseButton1Click event

Here are some steps:

1. Put a TextButton inside of your ScreenGui (if you already have one). If you don’t, create one inside the StarterGui. Name the button ‘MorphReset’

2. Create a LocalScript inside StarterPlayerScripts (located inside StarterPlayer)

3. Put the following in the script

local ScreenGui = game.Players.LocalPlayer:WaitForChild('PlayerGui', 20):WaitForChild('ScreenGui', 20)
local ResetButton = ScreenGui:WaitForChild('MorphReset')

ResetButton.MouseButton1Click:Connect(function()
	
	--Save the player's current position
	local cFrame = game.Players.LocalPlayer.Character.PrimaryPart.CFrame
	
	--Reload the character
	game.Players.LocalPlayer:LoadCharacter()
	
	--Send the player back to the position they were at
	game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(cFrame)
	
end)

When I tried this it said in the Output that LoadCharacter can only be called by the backend server

Right. That’s my mistake. You’ll need to create a remote function and fire a signal to the server telling it to reload the player. You can name the RemoteFunction whatever you want, but in this case I’ll use ReloadPlayer. Replace that line with the firing of the function and wait for it to return a value back before teleporting the player. Put a script inside ServerScriptService that is linked to the RemoteEvent with this code:

local ReplicatedStorage = game:GetService('ReplicatedStorage')

ReplicatedStorage.ReloadPlayer.OnServerInvoke = function(Player)
	Player:LoadCharacter()
	return true
end

Here is the reformatted code that should be in the LocalScript:

local ScreenGui = game.Players.LocalPlayer:WaitForChild('PlayerGui', 20):WaitForChild('ScreenGui', 20)
local ResetButton = ScreenGui:WaitForChild('MorphReset')

ResetButton.MouseButton1Click:Connect(function()
	
	--Save the player's current position
	local cFrame = game.Players.LocalPlayer.Character.PrimaryPart.CFrame
	
	--Reload the character
	local Received = game.ReplicatedStorage.ReloadPlayer:InvokeServer()

	--Send the player back to the position they were at
	game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(cFrame)
	
end)
3 Likes

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