I need help getting an understanding of how morphs work. Devforum and YouTube haven’t been helpful.
So, in my game players can spend currency to buy character models and then it goes into their inventory and they can equip it. These are r6 based models.
What I want to know is how to make it so when a player press the button to equip a morph in the inventory it’ll go over their normal player and delete any accessories they were wearing with a normal avatar. (Unless there’s a better way to do this). I also wanna set it up so a player will respawn with the morph still on and also spawn with it when joining the game (Could I use Datastores to achieve this? If so, how?).
I have zero clue how I would do this and YouTube & devforum haven’t been quite helpful.
2 Likes
Here is the code to spawn the player as the model
local function respawnPlayer(plr, model)
local model = game.ServerStorage:FindFirstChild(model) --This is the model that the player respawns as
local oldModel = plr.Character
local newModel = model:Clone()
newModel.Name = plr.Name
plr.Character = newModel
newModel.Parent = game.Workspace
newModel:SetPrimaryPartCFrame(game.workspace.Spawn.CFrame) -- replace Spawn with the respawing part location
for _, object in ipairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do -- this just copies all the scripts from startercharacterscripts, you can do this with player scripts too.
local newObject = object:Clone()
newObject.Parent = newModel
end
oldModel:Destroy()
end
Yes you can store the character morph with data storage, just store the name and call the function above with the name you stored
3 Likes
I love you bro (no homo). So how does this script work? I want the model to pretty much go on the player and they still have all the normal animations. I’m not trying to replace the default character or anything, merely place the model over it so it’s less work on my end. Does this do that? If so how can I set it up so when a player dies or respawns they’ll still have the model on? And when the leave and rejoin the model will still be on?
2 Likes
If you use this script it should respawn the player with all the normal animation. But if you want the player to be inside the suit, I think the best way is to make a dummy rig in the suit and use a script to update its appearance to the player
Also It doesn’t replace startercharacter
As long as it still runs all the normal movement animations then that works
Yea then it should be fine, just make sure the animate script is in the startercharacterscripts
The rig of the suit also has to match the player’s rig(Same names)
Yeah I’m just gonna replace all the default roblox animations with new custom ones for my game
Wait wdym rig? I’m lost. I’m just trying to make a model go over the default player model or replace it
Does the suit have a rig? Because if the suit doesn’t have a rig animations won’t work
Like motor3D
So do I need to rig every character model?
Yea, thats what I do for my game.
So if I’m reading everything right what I need to do is rig all 6 parts of the model. If a model is rigged will it have the game’s default animations?
Yea, it has to have the Left shoulder, Right shoulder, Root Hip, Neck, Left Hip, and Right Hip.
Just like a normal R6 rig
Okay so. Rig every model. Then when a player clicks equip in the inventory make it fire a remote event to run the code you showed me earlier?
You should run the code on a server script so other people can see, but yea.
Alrighty, so the script for the remote event will be on the server
One final thing. Can you walk me through exactly what the script you showed does? I wanna understand it so I can apply it in the future @purpledanx
1 Like
local function respawnPlayer(plr, model) -- arguments for the player that is respawing and the model the player morphs into.
local model = game.ServerStorage:FindFirstChild(model) --This is the model that the player respawns as
local oldModel = plr.Character -- this is the player's character
local newModel = model:Clone() -- cloning the model
newModel.Name = plr.Name -- changes the the models name to the player's name
plr.Character = newModel --set's player's character to the model we cloned
newModel.Parent = game.Workspace --parent's to workspace
newModel:SetPrimaryPartCFrame(game.workspace.Spawn.CFrame) -- set's the CFrame to the respawing pad
for _, object in ipairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do -- this just copies all the scripts from startercharacterscripts, you can do this with player scripts too. Just replace StarterCharacterScripts with StarterPlayerScripts
local newObject = object:Clone() -- clones the script
newObject.Parent = newModel -- parents it
end
oldModel:Destroy() -- destroys the old player character
end
does that work?
Yeah that helps explain things. What is the whole respawning pad thing?
And why am I copying and cloning starter scripts?