#Character flungs into sky after respawn-reset

1 messages · Page 1 of 1 (latest)

hollow pumice
#

Hello, i have noticed that my character sometimes not always flungs into the sky or some random position when they die or reset. What can cause this issue. Is it maybe cause of my teleport handling ?

hollow pumice
#

⁨```lua
local function teleportPlayersToMap(map)
local spawnPoints = map:FindFirstChild("SpawnPoints")
if not spawnPoints or #spawnPoints:GetChildren() == 0 then
return
end

local spawnPointsList = spawnPoints:GetChildren()

for _, player in ipairs(game.Players:GetPlayers()) do
    task.spawn(function()
        local character = player.Character
        if not character then
            local startTime = tick()
            repeat
                task.wait(0.1)
                character = player.Character
            until character or (tick() - startTime) > 5

            if not character then
                return
            end
        end

        local humanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
        if not humanoidRootPart then
            return
        end

        local randomSpawn = spawnPointsList[math.random(1, #spawnPointsList)]
        character:PivotTo(randomSpawn.CFrame * CFrame.new(0, 2, 0))
    end)
end

task.wait(1)

end```⁩

maiden wasp
#

What is this script for?

#

Why do you need to tp players?

#

Also when do you call this function?

#

Also for position you should use vector3 Imo

north barn
#

randomSpawn.CFrame * CFrame.new(0, 2, 0)⁩ is probably not going to have the results you wanted

maiden wasp
#

Was about to say that lol

hollow pumice
#

I am teleporting all players to random position when a specific button is clicked

maiden wasp
#

I'd recommend using vector3 or just random spawn.CFrame

#

Ur first issue is probably not to do with this script

#

Or if it is it's with the pivot to

north barn
hollow pumice
#

I found it guys! It was this script:

⁨```lua
local playSoundForLocalPlayer = game:GetService("ReplicatedStorage"):WaitForChild("PlaySoundForLocalPlayer")
local players = game:GetService("Players")
local debounce = {}

script.Parent.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local player = players:GetPlayerFromCharacter(character)
if humanoidRootPart and player and not debounce[player] then
local isPlayerInMap = character:FindFirstChild("PlayerInMap")

        if isPlayerInMap then
            if isPlayerInMap.Value == true then
                isPlayerInMap.Value = false
            end
        end
        
        debounce[player] = true

        -- Teleport player
        humanoidRootPart.Position = game:GetService("Workspace"):WaitForChild("LobbyTeleporter").Position + Vector3.new(0, 1, 0)
        playSoundForLocalPlayer:FireClient(player, script:WaitForChild("SplashWaterEffectSound"))

        task.delay(2, function()
            debounce[player] = false
        end)                
    end
end

end)

rich harborBOT
#

studio** You are now Level 7! **studio

hollow pumice
#

It is better using character:PivotTo instead of humanoidRootPart i guess

maiden wasp
#

Yuh

#

Or use cframe

#

Or vector 3

north barn
#

directly setting part.position unwelds/unconstrains the part during the move, so offsets change. you're left with a character whose root part can be very far away from the rest of the actual character

maiden wasp
#

Usually

north barn
#

ya if you want to move the whole assembly always set cframe not position

#

doesn't matter if you pivotto or set the part cframe, the whole assembly moves as one model in both cases

hollow pumice
#

Thanks a lot for offering help guys!

north barn
#

'it reduces lag'
i'm just ... going to pretend i didn't hear that.

north barn
hollow pumice
#

k never mind

north barn
#

nothing in your code could possibly be so bad that it drops framerate below 60fps, so you're fine.

hollow pumice
#

So, is there a more efficient way of teleporting like 10 players at once?

north barn
hollow pumice
#

Alright

maiden wasp
#

It's better to optimize now than later but yeah don't need to optimize for 100% especially not when you just started making a game

north barn
#

9 times out of 10 these micro 'optimizations' are extremely premature, or make things more difficult than they ever need to be

north barn
maiden wasp
maiden wasp
north barn
hollow pumice
#

I am actually optimizing my game right now, so i am closer to publishing it than a new start

north barn
#

start with some working prototype - and if there is a real performance problem, measure, try something, measure again.

#

don't be trying to fix performance problems that dont exist yet

#

it's all in the video so 👍

hollow pumice
#

okay