Pivot to doesn't position the character properly

Hello!
I have this problem with PivotTo(). When its fired it sometimes puts the character in a random position, I have tried to do the CFrame of the plate instead of GetPivot() but it has the same problems. Now when I teleport the humanoidrootpart, it works perfectly fine but now the tools won’t work.
pls help idk what to do!

for i, plate in pairs(game.Workspace.PlateFolder:GetChildren()) do
		for i, Player in pairs(game.Players:GetChildren()) do

			if plate.Name == Player.Name then
				if plate:GetAttribute("Placed") then
					local char = Player.Character
					task.wait()
					char:PivotTo(plate.CFrame * CFrame.Angles(math.rad(-90), 0, 0) + Vector3.new(0, 8, 0))
				else
					repeat task.wait()

					until plate:GetAttribute("Placed")
					local char = Player.Character
					char:PivotTo(plate.CFrame * CFrame.Angles(math.rad(-90), 0, 0) + Vector3.new(0, 8, 0))
				end
			end
		end
	end

I just need to make PivotTo() not teleport to a random location or get my tools fixed when I teleport the humanoidrootpart

the tools are just the classic weapons like: classic timebomb, classic rocketlauncher, classic lasergun

any help is appreciated!

1 Like

well there is a pivotT code

-- Define a function to handle character teleportation
local function teleportCharacter(char, position)
    local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
    humanoidRootPart.CFrame = CFrame.new(position)
end

-- Define a function to handle plate placement event
local function onPlatePlaced(plate)
    local player = game.Players:FindFirstChild(plate.Name)
    if player then
        local char = player.Character
        if char and char:FindFirstChild("HumanoidRootPart") then
            teleportCharacter(char, plate.Position + Vector3.new(0, 8, 0))
        else
            char = player.CharacterAdded:Wait()
            teleportCharacter(char, plate.Position + Vector3.new(0, 8, 0))
        end
    end
end

-- Connect the plate placement event to the function
for _, plate in pairs(game.Workspace.PlateFolder:GetChildren()) do
    if plate:GetAttribute("Placed") then
        onPlatePlaced(plate)
    else
        plate.AttributeChanged:Connect(function(attribute)
            if attribute == "Placed" and plate:GetAttribute("Placed") then
                onPlatePlaced(plate)
            end
        end)
    end
end

1 Like

Use the Position property of the plate’s BasePart instead of its CFrame to calculate the target position for teleportation and ensure that the character’s HumanoidRootPart is teleported to the target position. This should make that tools attached to the character work correctly after teleportation.

THank you so much i tried to fix it myself for a whole day, because im a beginner at scripting

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.