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

How could you make a seat that teleports someone to a block when they jump out?

Asked by 4 years ago

I've tried but keep failing :( I want it so when people jump out of my coaster they get teleported next to the station so they can't go on the track Does anyone have any ideas?

0
You can check is the Seat.Occupant is nil or not https://developer.roblox.com/api-reference/property/Seat/Occupant Block_manvn 395 — 4y

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

The solution to your answer is pretty simple, hope this helped. ^w^

Code below with explanation:

   local Players = game:GetService("Players")

        local seat = script.Parent --This means the script has to be in the seat.

        local currentPlayer = nil

        seat:GetPropertyChangedSignal("Occupant"):Connect(function()
            local humanoid = seat.Occupant 
            if humanoid then --if a player is sitting, then
                local character = humanoid.Parent
                local player = Players:GetPlayerFromCharacter(character)
                if player then 
                    print(player.Name.." has sat down")
                    currentPlayer = player --sets the player to currentplayer so that we can detect when they stand up
                    return
                end 
            end
            if currentPlayer then --if a player isn't sitting, then
            wait(0.5) --has to have a bit of delay otherwise the character seems to get flinged
                currentPlayer.Character:MoveTo(Vector3.new(20.46, 0.5, -26.17)) --after the wait is over, move the character to the given position. Obviously you can change this to whatever position you need.
                print(currentPlayer.Name.." has got up")
                currentPlayer = nil --sets it to nil so that another player can sit on it
            end
        end)

If this helped make sure to accept my answer. :3

0
U guys are amazing tysm x ATRGuestServices 5 — 4y
0
np uwu iOriena3 67 — 4y
Ad

Answer this question