I want to have my player unwelded from the elevator they were connected to, then be teleported to a new location.
What is the issue?
The player will not teleport directly after the weld has been removed.
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?
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.
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.
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.
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