1

# I made a teleport script and it doesn't work but there are no errors?

I made a simple script that teleports you to the spawnlocation when you touch a part, but for some reason the script doesn't work and there are no errors.

local Teleport = game.Workspace.SpawnLocation

script.Parent.Touched:Connect(function(plr)
plr.Character.HumanoidRootPart.CFrame = CFrame.new(Teleport.CFrame.X, Teleport.CFrame.Y + 5, Teleport.CFrame.Z)
end)


0
Edited 2 days ago

Hello! I am here to help. Usually, for teleport scripts, I use .Position, since whenever I use CFrame, it always returns an error about CFrame not existing, and I'm not sure why. Anyways, that is my recommendation. In addition, you would use a new Vector3 instead of making a new CFrame. Let me show you an example of what I use for teleport scripts.

local teleport = game.Workspace.TeleportDestination
local part = script.Parent

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
hit.Parent.Humanoid.Position = Vector3.new(teleport.Position.X, teleport.Position.Y + 5, teleport.Position.Z)
print('Success') --This will only print if the code runs correctly; if it does not print, then there was an error.
end
end)


Before using the script, make sure the spawn point is anchored. (it should be by default) Hope this helps!

EDIT: So after looking at your question again and the script, I realized you did:

script.Parent.Touched:Connect(function(plr)


Note that the .Touched event does not pass through the player arguement. Instead, it passes through the bodypart/part that touched the part. In this case, it would pass through probably the player's leg(s) as the bodypart. This would mean the parent would be the player's character. Therefore, do:

script.Parent.Touched:Connect(function(part)
local character = part.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
end)


Again, hope this helps!

0
Thanks for helping but it still seems to not work. Once again there are no errors. I tested it with a print("Hello") after the function: script.Parent.Touched:Connect(function(part) print('Hello') But nothing prints. I believe something is wrong with the function but I don't know what. Again thank you for the help! aydenwilson819 5 — 1d
0
Edited 1 day ago

Problem

You should read the description of the Touched event here. The Touched event comes with a parameter known as the part that otherPart. So, you're getting confused and think that the parameter is the player while it's not.

Fixed code

local Players = game:GetService("Players")
local Teleport = workspace.SpawnLocation

script.Parent.Touched:Connect(function(hitPart)
local character = hitPart.Parent

if character:FindFirstChild("Humanoid") then
character.HumanoidRootPart.CFrame = CFrame.new(Teleport.CFrame.X, Teleport.CFrame.Y + 5, Teleport.CFrame.Z)
end
end)


Explanation

First, I got the Players service. Why did I use the :GetService method while I could've done game.Players? Because if you changed the name, :GetService method would still work.

Line 2 is a variable for the destination.

Line 4 is connecting a Touched event to a function.

Line 5 is the character while sometimes it may not be.

Line 7 is to confirm if its character then we look at its children for a humanoid then if it return an Instance meaning it's true, otherwise, returns nil meaning false.

Line 8 is teleporting the character.

0
Hi thanks for helping but again it still doesn't teleport and it comes out with no errors. I don't know if it's a glitch or what but I have taken tutorials and still nothing happens. aydenwilson819 5 — 1d
0
@aydenwilson819 It works for me. When I tried your code, I don''t know how you didn't get an error because it errors for me. MarkedTomato 620 — 1d
0
@aydenwilson819 Screenshot your Output window to me. I feel like you don't know the output because you''d have got an error with your code. MarkedTomato 620 — 1d
0
Here is the link to the screenshot: file:///C:/Users/hyper/Videos/Captures/Untitled%20Game%20-%20Roblox%20Studio%209_16_2021%205_26_16%20PM.png aydenwilson819 5 — 22h
0
@aydenwilson819 Well, apparently I'm not on your computer. Post the image on gyazo.com . Also that's not a link that's the path to your screnshots in your files. MarkedTomato 620 — 18h