How to make a part teleport randomly behind player with delay?
Try this
local part = script.Parent -- the part to click and teleport
local theDelay = 3
local function tpPart(plr)
local playerPosition = plr.Character.HumanoidRootPart.Position
local playerDirection = plr.Character.HumanoidRootPart.CFrame.LookVector
local distanceBehind = -10 -- Distance behind the player to teleport the part
local randomOffset = Vector3.new(math.random(-5, 5), 0, math.random(-5, 5)) -- Random offset
local newPosition = playerPosition + (playerDirection * distanceBehind) + randomOffset
part.Position = newPosition
end
script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(plr)
task.delay(theDelay, function()
tpPart(plr)
end)
end)
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.