What do you want to achieve? A character selection screen that respawns the character as a new custom character.
What is the issue? Getting an error saying “Trying to index character with nil”
What solutions have you tried so far? Changing how the character is referenced, such as
local player = Players.LocalPlayer or game:GetService("Players")
local character = player.Character
Furthermore, I have tried premade default morphs that do not respawn the player. Using these breaks all touch interests, which makes most things impossible to interact with. However, click detectors do work.
The character I am trying to use is a mesh character, which has a humanoid and an invisible Roblox dummy inside. The character is basically an animated mesh skin over the default Roblox character.
Below is the script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local morphButton = script.Parent
local morphModel = ReplicatedStorage.C
local function respawnAsMorph()
local player = game:GetService("Players")
local character = player.Character
-- Remove the current character
if character then
character:Destroy()
end
-- Clone and spawn the morph model
local morphClone = morphModel:Clone()
morphClone.Parent = workspace
player.Character = morphClone
end
morphButton.MouseButton1Click:Connect(respawnAsMorph)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local morphButton = script.Parent
local morphModel = ReplicatedStorage.C
local function respawnAsMorph()
-- Clone and set the morph model as character
local morphClone = morphModel:Clone()
morphClone.Parent = workspace
player.Character = morphClone
morphClone:SetNetworkOwner(player)
end
morphButton.MouseButton1Click:Connect(respawnAsMorph)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local morphButton = script.Parent
local morphModel = ReplicatedStorage.C
local function respawnAsMorph()
-- Clone and set the morph model as character
local morphClone = morphModel:Clone()
morphClone.Parent = workspace
player.Character = morphClone
end
morphButton.MouseButton1Click:Connect(respawnAsMorph)
I can control the custom mesh character now but it’s focused on the normal character. It also teleports the character incorrectly. Is there a way to set the humanoid to the mesh character?
I believe this may be a Roblox issue where morphs cannot touch parts, even with a humanoid and canTouch on the humanoidRootPart, mesh, etc. I will be making a bug report on the matter.