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

How to make a teleport while sitting?

I'm making a camping game spinoff and i need help with a script when the car moves. When the car gets in the dark spot, it'll teleport. But it doesn't teleport when your sitting. When your sitting in the car, you are un-collidable. But when your not sitting, You are and you can teleport. Which makes you collidable. I made two scripts of it. But none of them worked. Here is the current script my dev team tried to fix :

-- Scripted by goldman201011 :3
--- 12/23/2019
 
local TeleportService = game:GetService("TeleportService")

local Place = 4535217403

 

script.Parent.Touched:connect(function(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

if player then

TeleportService:Teleport(Place, player)

   end

end)

Here is my script I made :

-- Scripted by Skylark011 :3
--- 12/22/2019

local TeleportService = game:GetService("TeleportService")
local ID = 4535217403

function onTouched(hit)
 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
 if player then
  TeleportService:Teleport(ID, player)
  end
end

script.Parent.Touched:Connect(onTouched)

So if you can help me, I'll really appreciate it.

2 answers

Only use TeleportService if you are teleporting players to a separate place. This has nothing to do with collision though, which confuses me about your problem.

If you want to set the position of the player, set the HumanoidRootPart’s CFrame.

2 comments

0

its supposed to use teleportservice. THE CAR is un-collidable. When you sit down in the car, you're un-collidable. Which makes the teleport not work. Even tried 2 kill scripts, guess what, it didn't work.

0

I don’t know what to say. The problem with your script does NOT have to do collision. Open the output window in your project and look if it gives an error. Note that you cannot be teleported within Roblox Studio, you must test the game for real.

I don't really understand the problem, but I created a script which detects a seat instead of a character, because uncollidable objects still fire the .Touched event.

Script Inside Part

local players = game:GetService("Players")

local TeleportService = game:GetService("TeleportService")
local ID = 4535217403

script.Parent.Touched:Connect(function(object)
	if object:IsA("Seat") or object:IsA("VehicleSeat") then--Checks if the object is a seat
		local occupant = object.Occupant
		if occupant then--Makes sure the seat has an occupant
			local character = occupant.Parent--Finds the character
			local player = players:GetPlayerFromCharacter(character)--Finds the player
			if player then--Makes sure there is a player
				TeleportService:Teleport(ID, player)--Teleports player
			end
		end
	end
end)

3 comments

0

I’ve read quite a bit about TeleportService and never did I see something having to do with collision...

0

Your right, I don't understand the problem. You just have to actually test it instead or roblox studio

0

tbh idrk why it said that i'm watching a tutorial its confusing me

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