Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix the teleporting problem when using CFrame?

Asked by 5 years ago

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

0
Post your script. nicktooner 119 — 5y
0
ok User#23793 0 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

  2. Insert a ServerScript Into StarterCharacterScripts

  3. 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.

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 User#23793 0 — 5y
0
Well you may have noticed I used CFrame instead of Position BlackOrange3343 2676 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
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

Answer this question