Problem with LoadCharacter()

I’m making a revive system using a proximity prompt, but when I use LoadCharacter, everything under it doesn’t print.

script.Parent.Triggered:Connect(function(plr)
	if script.Parent.Parent:IsA("Model") then
		if plr.Name == script.Parent.Parent.Parent.Name then
			print("himself")
		end
--	elseif plr.Character.Humanoid.Health == 0 then
--		print("nope")
	else
		local character = script.Parent.Parent.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		local Position = player.Character.UpperTorso.CFrame
		local part = Instance.new("Part")
		part.Name = character.Name
		part.Parent = game.Workspace
		part.CFrame = plr.Character.HumanoidRootPart.CFrame
		part.Anchored = true
		part.Transparency = 0
		part.CanCollide = false
		player:LoadCharacter()
		print("hi")
	end
end)

The function yields the script (presumably until the character has loaded) so it will probably only run once the character has loaded into the game.
Load character api

1 Like

This still works multiple times, but everything under the loadcharacter doesn’t run. I’m trying to make it so when the character loads it teleports back to where it was originally dead.

1 Like

As @Orbular3 stated, :LoadCharacter() is a yielding function. You could try setting up an event listener for LoadCharacter. To do this you could listen for appearance load.

player.CharacterAppearanceLoaded:Connect(function(character)

end)

Make sure you declare this event prior to the player:LoadCharacter() line, so that it doesn’t yield as well.