Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix the teleporting problem when using CFrame?

when I try to teleport the player's HumanoidRootPart using CFrame, the HumanoidRootPart is moving perfectly, but it's not connected to the body of the player (hands, arms, legs, etc..) please tell me how do I fix this please

2 comments

0

Post your script.

0

ok

2 answers

✓ Accepted answer

Hi, I'm BlackOrange and I will be helping you.

So, you don't actually need 2 scripts.

I will help you:

  1. Remove all the scripts you got for this respawn things and also remove the remote event (Optional)
  1. Insert a ServerScript Into StarterCharacterScripts
  1. Start by variables alone:
local Char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(Char)

-- This script will only run 1 time because it is in StarterCharacterScripts. This means you don't need an event. Unless there is a loop or event this will run 1 time

Char.Humanoid.Died:Connect(function()
	plr:LoadCharacter()
	wait()
	Char.HumanoidRootPart.CFrame = CFrame.new(plr.Checkpoint.Value.X,plr.Checkpoint.Value.Y+4,plr.Checkpoint.Value.Z)
end)

Char.Humanoid.HealthChanged:Connect(function(Health) -- this is backup incase Died doesn't work, I find Died fairly buggy
	if Health <= 0 then
		plr:LoadCharacter()
		wait()
		Char.HumanoidRootPart.CFrame = CFrame.new(plr.Checkpoint.Value.X,plr.Checkpoint.Value.Y+4,plr.Checkpoint.Value.Z)
	end
end)
--[[
Char.HumanoidRootPart.CFrame = CFrame.new(plr.Checkpoint.Value.X,plr.Checkpoint.Value.Y+4,plr.Checkpoint.Value.Z)]]--

Your Character should automatically respawn, this means you technically don't need :LoadCharacter()

Hopefully this helped.

Best of luck developer!

EDIT: Now works for instant respawn.

2 comments

0

I used :LoadCharacter() because I want the character to spawn instantly, and what I meant is not that, I meant when you teleport, your body falls off, but it does the moving animations when I move the HumanoidRootPart using my keyboard

0

Well you may have noticed I used CFrame instead of Position

game.ReplicatedStorage.Respawn.OnServerEvent:Connect(function(plr)
	wait(1)
	local human = plr.Character.HumanoidRootPart
	human.Position = Vector3.new(plr.Checkpoint.Value.X,plr.Checkpoint.value.Y+4,plr.Checkpoint.Value.Z)
end)

this code will be executed after this script:

local Humanoid = script.Parent:WaitForChild('Humanoid')
local plr = game.Players:GetPlayerFromCharacter(script.Parent)

Humanoid.Died:Connect(function()
	local stg = plr.Checkpoint.Value
	game.ReplicatedStorage.Respawn:FireClient(plr,plr)
	plr:LoadCharacter()
end)

it also receives it from a local script then that local script fires a server event that executes the first script above

This discussion is preserved as it was. New answers, comments, and votes are closed.