Hey there! So I recently put together a morphing GUI and as for the morphing part it works really well but I came across a few issues.
Firstly, when you click on the morphing button it teleports the player to the location of the model and I wanted to know how I could make it so that when they morph they morph in place.
Secondly, when the player morphs they lose all of the items that they picked up while playing but the tools that are in StarterPack are still kept in the inventory so I wanted to know how to solve this issue.
There are 2 scripts, first one is a normal script in ServerScriptService:
--Remote Event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Load = ReplicatedStorage.Load
local ChangeChar = ReplicatedStorage.ChangeChar
--On Event Functions
game:GetService("Players").PlayerAdded:Connect(function(Player)
local Morph = Instance.new("StringValue", script)
Morph.Name = Player.UserId .. "'s Morph"
Morph.Value = "DefaultAvatar"
end)
Load.OnServerEvent:Connect(function(Player, PlayerCF)
if script[Player.UserId .. "'s Morph"].Value ~= "DefaultAvatar" then
script[Player.UserId .. "'s Morph"].Value = "DefaultAvatar"
Player:LoadCharacter()
end
end)
ChangeChar.OnServerEvent:Connect(function(Player, Character,Morph, PlayerCF)
local Humanoid = Character:WaitForChild("Humanoid")
if script[Player.UserId .. "'s Morph"].Value ~= Morph.Name then
script[Player.UserId.. "'s Morph"].Value = Morph.Name
local A = Morph:Clone()
A.Name = Player.Name
Player.Character = A
A.Parent = game.Workspace
end
end)
And there is a Local Script inside the buttons that when you click on you morph into the rig:
--Remote Event
local ChangeChar = game:GetService("ReplicatedStorage").ChangeChar
--Variables
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Mouse Click Function
script.Parent.MouseButton1Click:Connect(function()
local Character = Player.Character
local Morph = ReplicatedStorage.RealPlayers[script.Parent.Name]
local PlayerCF = Character.LowerTorso.CFrame
ChangeChar:FireServer(Character,Morph,PlayerCF)
end)
And here are pictures to where items in the script are located:
I’m new to scripting and I would love if you guide me to what exactly I should do or replace, there isn’t any video explaining it so I figured I should put it here so it’s more specific!
ChangeChar.OnServerEvent:Connect(function(Player, Character,Morph, PlayerCF)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:UnequipTools()--Since this is the only point to getting Humanoid...
if script[Player.UserId .. "'s Morph"].Value ~= Morph.Name then
script[Player.UserId.. "'s Morph"].Value = Morph.Name
local A = Morph:Clone()
A.Name = Player.Name
Player.Character = A
A.Parent = game.Workspace
end
end)
--Remote Event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Load = ReplicatedStorage.Load
local ChangeChar = ReplicatedStorage.ChangeChar
--On Event Functions
game:GetService("Players").PlayerAdded:Connect(function(Player)
local Morph = Instance.new("StringValue", script)
Morph.Name = Player.UserId .. "'s Morph"
Morph.Value = "DefaultAvatar"
end)
Load.OnServerEvent:Connect(function(Player, PlayerCF)
if script[Player.UserId .. "'s Morph"].Value ~= "DefaultAvatar" then
script[Player.UserId .. "'s Morph"].Value = "DefaultAvatar"
Player:LoadCharacter()
Player.Character.LowerTorso.CFrame = Player
end
end)
ChangeChar.OnServerEvent:Connect(function(Player, Character,Morph, PlayerCF)
local Humanoid = Character:WaitForChild("Humanoid")
if script[Player.UserId .. "'s Morph"].Value ~= Morph.Name then
script[Player.UserId.. "'s Morph"].Value = Morph.Name
local A = Morph:Clone()
A.Name = Player.Name
Player.Character = A
A.Parent = game.Workspace
Player.Character:WaitForChild("LowerTorso").CFrame = PlayerCF
end
end)
--Remote Event
local ChangeChar = game:GetService("ReplicatedStorage").ChangeChar
--Variables
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Mouse Click Function
script.Parent.MouseButton1Click:Connect(function()
local Character = Player.Character
local Morph = ReplicatedStorage.RealPlayers[script.Parent.Name]
local PlayerCF = Character.LowerTorso.CFrame
ChangeChar:FireServer(Character,Morph,PlayerCF)
end)