Annoying problem with simple teleportation script

Hello,

So I have a server script inside a radio where when the radio’s proximity prompt is triggered, it will play a sound, when the sound is finished, the lights will turn off and the game will teleport the player by getting the character and doing SetPrimaryPartCFrame to a pad about 2 seconds later, here is the script:

local radio = script.Parent
local dialogue = radio.Dialogue
local proximity = radio.ProximityPrompt
local light = game.Workspace:WaitForChild("darkroomlight").Model.Model.Bulb.PointLight
local JailedOfficePad = game.Workspace.JailedOfficePad
local currentlyTeleporting = game.StarterPlayer.StarterCharacterScripts.currentlyTeleporting
debounce = false

proximity.Triggered:Connect(function(triggered)
	proximity.Enabled = false
	dialogue:Play()
	dialogue.Ended:Wait()
	task.wait(2)
	light.Enabled = false
	task.wait(2)
	print("woohooo")
	if triggered and triggered.Parent and triggered.Character:FindFirstChildWhichIsA("Humanoid") and currentlyTeleporting.Value == false then
		local Character = triggered.Character
		local teleportLocation = CFrame.new(JailedOfficePad.CFrame.X, JailedOfficePad.CFrame.Y + 5, JailedOfficePad.CFrame.Z)
		local player = game.Players:GetPlayerFromCharacter(triggered.Parent)
		local teleportingValue = currentlyTeleporting
		Character:SetPrimaryPartCFrame(teleportLocation)
		local teleportingValue = currentlyTeleporting
		teleportingValue.Value = true
		script:Destroy()
		debounce = false
	end
end)

The problem I’m facing with this is that the script stops working mid way (after the lights turn off) and fails to teleport you. I discovered that the line

if triggered and triggered.Parent and triggered.Character:FindFirstChildWhichIsA("Humanoid") and currentlyTeleporting.Value == false then

was causing this due to the way it was placed in the script, and when I removed it, the script DID teleport you to the pad, but the character ends up no clipping through the floor for some weird reason after teleported even though the floor has CanCollide enabled. Here’s a clip of what it looked like before said line was removed from the script:

And here’s a clip after the line was cleared from where it was:

I’m not sure why it’s doing this if it doesn’t do this with the other teleportation pads that also have the same script (just without the line deleted). All that was changed here was

if triggered and triggered.Parent and triggered.Character:FindFirstChildWhichIsA("Humanoid") and currentlyTeleporting.Value == false then

getting removed and also removing the end that was at the bottom of the script. Here’s the pad that you get teleported on:

I don’t think that it’s too low and that being the reason why it’s making the character fall through the floor as I have other teleportation pads (just with the line not deleted) also placed like this on the ground and you get teleported on top of it with no problem. I tried raising it a bit higher this time but the script still seems to clip the player through the ground! I’d really really appreciate your help on this as I’ve been stressing over it a bit for the past few days knowing it’s something so simple which I can’t seem to fix.

1 Like

Dont do SetPrimaryPartCFrame
Do this:

Character:MoveTo()

why not Character:PivotTo(location.CFrame)

1 Like

Character:MoveTo simply moves. or teleports the player, not to be confused with Character.Humanoid:MoveTo, they work the same way except one teleports the player, but both dont require the PrimaryPart.

All thats really need is:

Character:MoveTo(teleportLocation)
1 Like

Character:MoveTo() Didn’t really seem to do anything as the game didn’t know what coordinate to move it to.

Still same result, it teleports the player but for some reason ends up making the player no clip through the floor again.

Make sure you are using Position, not CFrame.

instead of CFrame.new, its Vector3.new
get the Position on the world or Part and teleport the player there

So Here is what you can do:

local teleportLocation = JailedOfficePad.Position + Vector3.new(0,5,0)
Character:MoveTo(teleportLocation)

I assure you this works as i use it in my games.

1 Like

“The problem I’m facing with this is that the script stops working mid way (after the lights turn off) and fails to teleport you. I discovered that the line”
I think the reason why that happened is because you were destroying the script shortly after

if triggered and triggered.Parent and triggered.Character:FindFirstChildWhichIsA("Humanoid") and currentlyTeleporting.Value == false then
		local Character = triggered.Character
		local teleportLocation = CFrame.new(JailedOfficePad.CFrame.X, JailedOfficePad.CFrame.Y + 5, JailedOfficePad.CFrame.Z)
		local player = game.Players:GetPlayerFromCharacter(triggered.Parent)
		local teleportingValue = currentlyTeleporting
		Character:SetPrimaryPartCFrame(teleportLocation)
		local teleportingValue = currentlyTeleporting
		teleportingValue.Value = true
		**script:Destroy()**
		debounce = false
	end

You could also then use this instead for teleporting the player to the part

root.CFrame = CFrame.new(workspace.omg.CFrame.X, workspace.omg.CFrame.Y + 5, workspace.omg.CFrame.Z)

Maybe try and make the part you get teleported onto is not on the ground and see what happens then as well just in case.

1 Like

The Script runs everything except debounce due to it being after script:Destroy(), Therefore it wont set to false as the script will be destroyed before it can do it.
So that shouldnt be the case unless debounce is important.

1 Like

It could just simply be the way the part is positioned but I really don’t see anything else in the script that would cause the player to fall through the ground.

@CreativityMen @EchoWinds
Not sure if this is a better why of doing it but it automatically teleports the Player without needing a HumanoidRootPart

I dont use HumanoidRootPart to teleport players as it has its own set of issues moving it so it may not be as i think but it is a way of Teleportation.

1 Like

Most definitely should use :PivotTo(), so that you ensure you will be teleported to the exact location, and MoveTo, will try to position you as near to the position accounting for collision.

The trick is, however, to make sure you adjust the Y value of the teleport destination based on the size of the character.

lets assume teleport destination is x,y,z

for the y do
y + Humanoid.HipHeight + (HumanoidRootPart/2) +.5 this should teleport the character .5 studs above the destination (the reason I add a .5 is because most teleport destinations are centered on a 1 stud thick (in y direction) block, so .5 extra is needed to account for the target position being .5 studs into the target block.

I forgot to add, that even if a part is solid, and can collide, if you pivot to with cframe into it, you will fall through it, that is why it is important to make sure you teleport ‘above’ the target block.

1 Like

Sorry for the late reply, DevForum site was acting goofy.

Ok, so the position of the part in my game is in 1535.31, -307.61, 421.614 now, it’s high enough off the ground for the player to definitely spawn at. How would exactly would I set it up in the script so you get teleported like that? I had tried doing

local teleportLocation = JailedOfficePad.Position + Vector3.new(1535.31, -307.61, 421.614)

But that just made you spawn WAAAY off and killed you.

I also changed

local teleportLocation = CFrame.new(JailedOfficePad.CFrame.X, JailedOfficePad.CFrame.Y + 5, JailedOfficePad.CFrame.Z)

to

as suggested. Sorry, still a bit confused as it didn’t seem to work.

I’ve tried raising it before and the player still seemed to fall through the ground, I haven’t been sure why yet.

How exactly would that be in my script? The teleportLocation variable looks like this now:
(Still on the ground)

local teleportLocation = JailedOfficePad.Position + Vector3.new(1535.31, -310.56, 421.614)

I tried adding the extra stuff after y as you suggested but it gave me this error
image

Why could that be?

1 Like

the floor is too thin, make the floor part thicker and you won’t fall through

Nope, just tried making it much thicker and you still fall through. The dark room in the beginning of the clip has a thin floor about as thin as the office one and you don’t fall through that one when they also use the same script for teleportation to locations.

Hi, Yeah I believe I made a mistake with that,

Maybe do these:

Method 1
local teleportLocation = JailedOfficePad.Position
character:MoveTo(teleportLocation + Vector3.new(0,2,0))

You Don’t Add a Position to a Position, in this case, you just add 2y and you wont spawn inside the part

Method 2
local teleportLocation = Vector3.new(1535.31, -310.56, 421.614)
character:MoveTo(teleportLocation)

In this example, you can just use Position, this isn’t the most efficient way due to you have to change it when you make a change to the game but it works either way.

You dont need to do this. either way it does the same thing as
teleportLocation.Position

Why are you doing division?

I tried to make a copy with your example and made some changes to the script, and it seems to work.
See if this helps you any.
RadioPlaysAndTeleports.rbxl (39.1 KB)
image

The script had some checks that were not necessary, also ‘where’ you were checking was out of place.

local radio = script.Parent
local dialogue = radio.Dialogue
local proximity = radio.ProximityPrompt
local light = game.Workspace.Bulb.SpotLight
local JailedOfficePad = game.Workspace.JailedOfficePad

proximity.Triggered:Connect(function(triggered)
	local Character = triggered.Character
	if Character and Character:FindFirstChildWhichIsA("Humanoid") and not Character:GetAttribute("TeleportingValue") then
		Character:SetAttribute("TeleportingValue",true)
		proximity.Enabled = false
		dialogue:Play()
		dialogue.Ended:Wait()
		task.wait(2)
		light.Enabled = false
		task.wait(2)
		print("woohooo")
		local teleportLocation = JailedOfficePad.CFrame+Vector3.new(0,Character.Humanoid.HipHeight + (Character.PrimaryPart.Size.Y/2) +.5)
		Character:PivotTo(teleportLocation)
		script:Destroy()
	end
end)
1 Like

LOL, turns out that the whole time it wasn’t even the script it was a part in Workspace that was covering the entire office which made you fall down after you teleported in.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.