Player cannot be teleported right after being unwelded

  1. What do I want to achieve?

I want to have my player unwelded from the elevator they were connected to, then be teleported to a new location.

  1. What is the issue?

The player will not teleport directly after the weld has been removed.

  1. What solutions have you tried so far?

I have tried calling the teleport functions at the end of the Unweld function to ensure the character was unwelded first. I have also tried using “repeat wait() until weld == nil” and similar wait loops.

I would like to avoid using a plain wait(-) after the Unweld function, and instead would prefer some guaranteed way to fire the teleport after the player can move.

Important Code:

local function WeldPlayers()
	for _, player in pairs(game.Players:GetPlayers()) do
		local weld = Instance.new("WeldConstraint")
		weld.Name = "ElevatorWeld"
		weld.Parent = player.Character.PrimaryPart
		weld.Part1 = player.Character.PrimaryPart
		weld.Part0 = elevator.PrimPart
	end
end


local function TeleportPlayers(part)
	for _, player in pairs(game.Players:GetPlayers()) do
		player.Character.PrimaryPart:PivotTo(part.CFrame)
	end
end

local function UnweldPlayers()
	for _, player in pairs(game.Players:GetPlayers()) do
		player.Character.PrimaryPart["ElevatorWeld"]:Destroy()
	end
end

prompt.Triggered:Connect(function()
	prompt:Destroy()
	script.Gate:Play()
	wait(1)
	gateTween:Play()
	wait(5)
	elevator.CollisionGate.CanCollide = true
	TeleportPlayers(elevator.SpawnPlayers)
	wait(1)
	elevator.GateFinalPos.Union1.Transparency = 0
	elevator.GateFinalPos.Union.Transparency = 0
	gate.Union.Transparency = 1
	gate.Union1.Transparency = 1
	elevatorTween:Play()
	script.Elevator:Play()
	wait(7.9)
	InvokeAllPlayers(0.4, 1.5, 6)
	script["Metal Creak 1"]:Play()
	wait(2)
	InvokeAllPlayers(0.4, 5, 10)
	WeldPlayers()
	elevatorTween2:Play()
	script["elevator crash"]:Play()
	wait(1.5)
	InvokeAllPlayers2(1.5, -1)
	wait(1.4)
	script["elevator crash"]:Stop()
	game:GetService("Lighting"):WaitForChild("Atmosphere").Density = 0
	UnweldPlayers()
	TeleportPlayers(workspace.FacilitySpawn)
	InvokeAllPlayers2(1.5, -0.1)
end)

How can I know when the weld has stopped limiting the player’s movement?

1 Like

wait is deprecated, use task.wait instead, although this is not the answer

Have you tried using PVInstance:PivotTo() on the characters themselves?

local rns = game:GetService("RunService")
--
--
local function UnweldPlayers()
	for _, player in pairs(game.Players:GetPlayers()) do
		player.Character.PrimaryPart["ElevatorWeld"]:Destroy()
		while player.Character.PrimaryPart:FindFirstChild("ElevatorWeld") do
			rns.Stepped:Wait()
		end
	end
end

This may fix that. Destroying the weld doesn’t instantly update physics and player movement. The engine may need a frame or two to process the removal and resolve constraints.

1 Like

Oh that does seem to be the issue, you only need to wait for the RunService.PreAnimation phase or later though.

Also I don’t think your code would work, Instance:Destroy() sets the parent to nil, meaning you won’t find it.

Maybe try Player.Character:MoveTo()

Hmm …

while player.Character.PrimaryPart:FindFirstChild("ElevatorWeld") ~= nil do
	rns.Stepped:Wait()
end

That should cover it…

1 Like

No that doesn’t change anything, Destroying sets the parent of the instance to nil immediately, FindFirstChild will return nothing because it isn’t a child of the parent anymore.

The solution for OP is to destroy all the welds, wait for the PreAnimation phase (or later if you prefer), then teleport them.

That’s what I’m trying to do. How can we make that roll a few frames.
for loop for a bit with a stepped… maybe.

You only need to wait for the PreAnimation phase of the frame, you don’t need to wait more than that.

Show it… post the code for that.

local RunService = game:GetService("RunService")

-- Destroy welds here

RunService.PreAnimation:Wait()

-- Teleport here

Why do I have to goat you to show your code… Why don’t you just reply to the OP with your scripts.

Why should I need to write code for basic concepts?

Kind of the point of trying to figure out how to help someone.
That is your goal here isn’t it?

Sorry I guess I’ll need to write code to explain how to add two numbers together.

I explained how to solve the problem to the OP, I do not need to spoon feed code to people, we can end this here.

1 Like

I’m not sure helping others is a good fit for you. Egos aside this guy just wants something that works.

What @nowodev did was right. He answered correctly, there is no need to send the full code, as nobody is gonna learn from it. No need to fight.

His first post or the one he was lead to? Sorry, if I find a rude person rude. (this is far from the 1st time) I’ve had this problem and knew that could be the issue here, I solved mine with a task.wait(2). Always willing to learn something new to me. Just not with so much ego and, we still don’t know if this was fixed. If you think you might know how to fix something just post it… There is no need to try and belittle others in the post. Passive aggressive is just being rude.

1 Like

I tried waiting for PreAnimation, however to character is still unable to be teleported. I even tried removing the function and putting the Unweld() for loop inside the sequence of events, but that hasn’t worked either. It seems like the weld needs multiple frames to update.

Edit: Using “wait for heartbeat” twice seems to do the trick

RunService.Heartbeat:Wait()
RunService.Heartbeat:Wait()
1 Like