Ad
Log in to vote
0

Why isn't HumanoidRootPart not teleporting?

Asked by 11 months ago

Hello there, So I'm trying to teleport a player to a certain part using HumanoidRootPart after the timer is over. But it doesn't seem to work.

Here is the script:

local roundLength = 5
local intermissionLength = 5
local InRound = game.ReplicatedStorage:WaitForChild("inRound")
local Status = game.ReplicatedStorage:WaitForChild("Status")
local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn

InRound.Changed:Connect(function()
    wait(1)
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
        end
    else
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
        end
    end
end)



local function roundTimer()
    while wait() do
        wait(4.5)
        for i = intermissionLength, 1, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "Next minigame in: ".. i ..""        
        end
        wait(4.5)
        for i = roundLength, 1, -1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Time left: ".. i .." seconds!"
        end
    end
end
spawn (roundTimer)

I did a research and tried to Google it but nothing seems to work. Thank you!

0
It works NoelGamer06 65 — 11mo
0
Use Model:MoveTo() or Model:SetPrimaryPartCFrame(). I suggest you choose the latter (or second) since it tracks both your position and orientation. Dovydas1118 1475 — 11mo
0
@NoelGamer06 , doesn't seem to work for me though. iSimonPlayz 0 — 11mo
0
@Dovydas1118 , so I tried to do it but it doesn't work could you maybe send me how you did it? iSimonPlayz 0 — 11mo
View all comments (2 more)
0
I'm almost certain it's because your script is unable to actually execute the signal. You should be using a coroutine instead of the spawn() function. DeceptiveCaster 3761 — 11mo
0
@DeceptiveCaster , I created the coroutine and now it works, thanks! iSimonPlayz 0 — 11mo

1 answer

Log in to vote
0
Answered by 11 months ago
Edited 11 months ago

When setting a CFrame value you need to set it to the "CFrame.new" data type. Example:

char.HumanoidRootPart.CFrame = CFrame.new()

CFrame accounts for both position and orientation, so when you set something else to a CFrame you need to account for this. If I were you I would do

``char.HumanoidRootPart.CFrame = CFrame.new(GameAreaSpawn.Position)

That will set only the position of the player if you wanted to also set their orientation just add another value to the argument section.

I'm pretty new to Lua scripting, but as far as I can tell that's your problem, but I may have missed something.

0
You don't need to use CFrame.new() to set CFrame virushunter9 603 — 11mo
0
My bad, yea thats my fault, disregard my answer above. generalYURASKO 137 — 11mo
Ad

Answer this question