How to prevent death of the model the player.Character changed TO?

Simple task: swap out the current character for a clone of the character on a horse.

What’s happening: the moment I make the switch, the player dies. No loss of health. No triggering of Humanoid.Died. Not even falling over dead, I just see a red flash and reset a few seconds later.

Steps: I have a riderless horse. I clone the player, and rebuild the player on the horse. I set the camera. I add the animate script. All errors squashed. I make the swap and die. I’ve had the same results making the swap on client and server, but server works better.

There’s a second version, where I embrace the death… force it with loadcharacter. I hate this version because there is a split second where the camera goes back to the spawn point. Still completely wrong, but at least I stay on the horse. (can I eliminate that split second teleport making it super obvious they just died?)

Both versions are based on recommendations I found here on devforum.

I’m very close! Any ideas where I went wrong? Can I shut down death?

Version 2:

Latest code. For Version 2, I probably don’t need to move animate, since I am killing the character intentionally.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mountModule = require(ReplicatedStorage.MountManagement)

local test = game.Workspace.TestHorse
local db = true  --debounce

test.PrimaryPart.Touched:Connect(function (hit)
	if db then
		db = false
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if  plr then
			game.Players.CharacterAutoLoads = false --VERSION 2
			mountModule.prepMount(plr,test)
			plr:LoadCharacter()  --VERSION 2
			plr.PlayerGui.UpdateCam:FireClient(plr,test.PrimaryPart)
			test.Name = plr.Name
			local animate = plr.Character.Animate		
			plr.Character = test --causes death
			animate.Parent = plr.Character
		end
		wait(1)
		db = true
		game.Players.CharacterAutoLoads = true --VERSION 2
	end
end)
3 Likes

I held onto this for hours looking for a solution, and found it 10 minutes after finally posting.

What actually happens is this: Humanoid is killing the model when “control” changes. Leave a model, it dies. Enter a model, it dies too. I was killing both models with the swap. Unsure if this is intended behavior.

The solution is to add the Humanoid object after the character swap (Version 1). That meant setting WalkSpeed and HipHeight via script.

EDIT 12/3: If you are finding this thread and want to know how to save the model changed FROM, that is easier. After the switch, you simply set its parent to the Workspace (is it currently “nil” and is headed for limbo!).

Can also clone the FROM, but not necessary.

See this post:

12 Likes

I know this is almost a year after but you’ve just saved a life!

4 Likes

my character doesnt work please help