Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a portal that teleports both a vehicle and the driver?

Asked by 4 years ago
Edited 4 years ago

When a vehicle touches a normal portal, it gets teleported to another location, but it leaves the driver by himself since the player doesn't touch it. I was trying to find a way to also teleport the driver onto the vehicle once the vehicle moves to the destination. This was my code, but it didn't seem to work in play mode.

local destination = workspace:WaitForChild("Destination")

function Touch(hit)
    print ('hit') 
    if script.Parent.Locked == false then -- Checks debounce
        if not hit.Parent:IsA("Accessory") then
            if hit.Parent.Name == "Car" then
                print ("Car detected")
                local SeatWeld = hit.Parent:WaitForChild("VehicleSeat"):FindFirstChild("SeatWeld")
                if SeatWeld then 
                    local character = workspace:FindFirstChild(SeatWeld.Part1.Parent.Name)
                    print (character)
                    character:moveTo(destination.Position)
                    hit.Parent:moveTo(destination.Position) 
                end
            end
        end
    end

    script.Parent.Locked = true
    wait(0.1)
    script.Parent.Locked = false
end 

script.Parent.Touched:connect(Touch) 

Sorry, the code gets messy when I paste it here. Ignore the script.Parent.Locked parts, that's just for debounce. I made sure all the names were entered in correct, and when it got down to the "print(character)" line, it printed the correct character. However, it didn't teleport the character to the destination.

I'm stumped. Any help would be greatly appreciated!

Answer this question