Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

1 answer

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

2 comments

0

U guys are amazing tysm x

0

np uwu

This discussion is preserved as it was. New answers, comments, and votes are closed.