I’m Trying to teleport a car in roblox from one spot to another once it becomes unoccupied, I did everything trouble shoot works perfectly fine with printing anything but the car stays at place and doesn’t bother to move, no errors at all. Any help?
Client Sided Code
local vehicle = game.Workspace.gpkart1
local driverSeat = vehicle.DriveSeat
local remoteEvent = game.ReplicatedStorage.Kart
local function OnOccupantChanged()
if not driverSeat.Occupant then
print("unoccupied")
wait(2)
remoteEvent:FireServer()
print("Teleported")
else
print("occupied.")
end
end
if driverSeat then
driverSeat:GetPropertyChangedSignal("Occupant"):Connect(OnOccupantChanged)
end
The teleport is directed towards a block that returns the kart to once the player leaves the kart (It’s a part of the Obby, I’m trying to keep this simple)
I’ve tried to Do PivotTo, But It only works once, again tried many debuggings and it didn’t work, what’s Thre to fix?
I have an obby with vehicles, and I was looking at the code for my cars to see how they were done.
(not my code) The code in the button that spawns the car, keeps a backup, so when it is clicked again, it destroys the current car, then respawns a copy of the backup.
Also it sets the car in Debris, so that after 10 minutes it will be destroyed anyway.
So if you can’t seem to get the :PivotTo working for you, maybe you should simply :Destroy() the car when the player gets out of the driver seat, and just spawn a backup copy when a new player needs a car.
Here is the code from the car spawn button from my obby, maybe this will help
local debris = game:GetService("Debris")
local car = script.Parent.Parent:WaitForChild("Vehicle")
local backup = car:Clone()
car:Destroy()
local button = script.Parent
button.BrickColor = BrickColor.Green()
local enabled = true
button.Touched:Connect(function(part)
if part and part.Parent and part.Parent:FindFirstChild("Humanoid") then
if enabled then
enabled = false
button.BrickColor = BrickColor.Red()
wait(1)
car = backup:Clone()
car.Parent = workspace
debris:AddItem(car,600)
wait(10)
button.BrickColor = BrickColor.Green()
enabled = true
end
end
end)