Teleport script will not work

So, this is a script for a main menu for a obby game. It basically allows you to choose which obby you want to play in. It broke. Any ideas why it broke/how to fix it? Also, if you can, Can you show me how to make a version of the script where it only fires if a gamepass is owned?

Here is the script:

function onTouched(hit)  
  print("Teleport")
  local human = hit.Parent:findFirstChild("HumanoidRootPart")
  brick = script.Parent
  if (human ~=nil) then
    human.CFrame= CFrame.new(Vector3.new(248, 158, 90))--Replace this with the location you want to telport to.-
   end
end

script.Parent.Touched:connect(onTouched)

Could you provide any errors you get in the output?

Just on the side, you might want to add a Debounce to your function to stop it running more times than you want it to (for example, both legs touch the brick, it fires twice).

If you want to check for gamepasses, you can simply add a conditional statement that uses the following documentation:

Give that a read and hopefully you’ll be all set.

Hope this helps,
-Tom :slight_smile:

1 Like

I have tested, there are no errors in the script page or output.

And, Yea, ill add that when I get this fixed.

Does anything print at all?

If not then it might be a case that your script isn’t being executed. Check that there are no errors elsewhere in the script that would terminate execution, and if that’s all good make sure the script is enabled and in an environment which it will work.

This is likely to be server side, if it’s a server script make sure it’s in the Workspace, ServerScriptService, or something that allows for execution of server side scripts.

Hope this helps,
-Tom :slight_smile:

Only thing printing is Teleport (i told it to print teleport on the second line)

You can use character:MoveTo() instead. I am pretty sure it uses position and not CFrame, so you will have to change it to that.

About making the teleportation “gamepass-exclusive” you can use PlayerOwnsAsset (however I don’t know if it’s the best way to do it)

How would i incorporate that into the menu? (I am new to scripting and I have not gotten the chance to learn much because of school)

Sorry, but I didn’t understand. Incorporate what into what menu?

1 Like

The script. What would I need to add onto it.

Perhaps try seeing whether the conditional statement that checks whether the variable “human” is nil or not is returning true and not false, that could be the issue.

Hope this helps,
-Tom :slight_smile:

1 Like

This should work.

local debounce = false
function OnTouched (hit)
    if not debounce then
        debounce = true

        print("Teleport")
        local human = hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart")
        --brick = script.Parent
        if human then
            human.CFrame = CFrame.new(Vector3.new(248, 158, 90)) --Replace this with the location you want to telport to.-
        end

        debounce = false
    end
end

script.Parent.Touched:Connect(OnTouched)

To make it work with a gamepass I would need to know how you are handling gamepasses in code. But it’s not complicated.

If you haven’t created a gamepass yet, here’s how to do it.

2 Likes

Alright. Thank you! I will definitely try that out!

With this you can do the teleportation with a menu GUI

local Player = game:GetService("Players").LocalPlayer
local character = Player.Character

local teleport = function ()
	local hrp = character:WaitForChild("HumanoidRootPart")
	hrp.CFrame = CFrame.new(Vector3.new(248, 10, 90))
end

script.Parent.Activated:Connect(teleport)

It only works on a localscript. You can prove it by doing this.
image

However this could fail, it all depends on what the other scripts do or how you configure your game. Then you would have to make a more sophisticated script. You can always ask on the forum.