How do I fix the bounce or jittering a player does when they are being teleported to another part?
I am also trying to make the players distance themselves from each other, so as to not make them stack after being teleported.
local TP1 = game.Workspace.Spawns.Spawn1
local TP2 = game.Workspace.Spawns.Spawn2
local TP3 = game.Workspace.Spawns.Spawn3
local MainFloor = game.Workspace["Main Floor"]
local rand = Random.new()
TP1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
task.wait(5)
local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
HumanoidRootPart.CFrame = MainFloor.CFrame + Vector3.new(rand:NextInteger(1, 5), 2 , rand:NextInteger(1, 15))
end
end)
TP2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
task.wait(7)
local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
HumanoidRootPart.CFrame = MainFloor.CFrame + Vector3.new(rand:NextInteger(1, 10), 2 , rand:NextInteger(1,10))
end
end)
TP3.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
task.wait(10)
local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
HumanoidRootPart.CFrame = MainFloor.CFrame + Vector3.new(rand:NextInteger(1, 15), 2 , rand:NextInteger(1, 5))
end
end)
I believe it’s because they are being spawned ever so slightly in the ground, which is why they are forced up and hence appear to bounce. You can try increasing the Y offset of the teleport a little bit, or come up with some other way to ensure the Y offset is sufficient regardless of the character
I have already adjusted the Y offset and it still does the same, not to mention the brown block to which the players are teleported to has collision turned off.
.Touched events fire everytime a part of a rig collides with the main part, and maybe the reason this is happening is because the teleporting is constantly invoken because you don’t check if they’ve been already touched or not.
-- NOT tested in Studio; might have issues
local debounce = {}
local function smartRemove(t:{}, obj:Instance)
for i, v in pairs(t) do
if v == obj then
table.remove(t, i)
break
end
end
end
["Part1"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not table.find(debounce, hit.Parent) then
table.insert(debounce, hit.Parent)
-- Teleport
task.wait(desiredTime)
smartRemove(debounce, hit.Parent)
end
end)
You, of course, can make multiple debounce tables if you wish to have one for each of the parts separately.
Yes, you understood my code perfectly.
It adds the hit.Parent to the debounce table, so it cannot fire again if it matches up, while also allowing for global debounce (so you can use X while Y is still debouncing)
As for the jittering, I believe the absence of debounce is the problem shown in the first video, and I aimed my response specifically for that problem.