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

Im trying to make a teleport, teleport you if u have the game pass. can anyone help me?

I've bin trying to make the teleport work so you get teleported if you have the game pass but the teleport isn't working at all, i keep getting frustrated on trying fixing it.

Heres the script

local Model         =   "teleporter1b";
if gamepassId        =   299858716;

local MPS           =   game:GetService("MarketplaceService");

local function Check(Player)
    return MPS:PlayerOwnsAsset(Player, passId);
end

script.Parent.Touched:connect(function(Touched)
    if Touched.Parent ~= nil and Touched.Parent:FindFirstChild("Humanoid") ~= nil then
        local tTo       =   script.Parent.Parent:FindFirstChild(Model);

        if tTo ~= nil then
            if Check(game.Players:FindFirstChild(Touched.Parent.Name) then

                local location      =   {tTo.Position};
                local i             =   1;

                local x             =   location[i].x;
                local y             =   location[i].y;
                local z             =   location[i].z;

                x                   =   x + math.random(-1, 1);
                y                   =   y + math.random(2, 3);
                z                   =   z + math.random(-1, 1);

                local lx            =   0;
                local ly            =   y;
                local lz            =   0;

                Touched.Parent.Torso.CFrame         =   CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz));
                script.Parent.Enabled.Value         =   0;
                tTo.Enabled.Value                   =   0;

                wait(3)

                script.Parent.Enabled.Value         =   1;
                tTo.Enabled.Value                   =   1;
            else
                print("Insufficient permissions.");
            end
        else
            print("Could not find teleporter!");
        end
    end
end)


1 comment

0

What's with all the huge gaps between declaring a variable and their values? Not helpful when reading it...

1 answer

Errors:

  • on line 2: you tried to declare gamepassId as a variable but you put "if" ? should be "local"
  • on line 7 you said passId when it should be gamepassId
  • on line 15 you didn't close the check()
  • on line 17 - 22 you make the position be in a table even though its just 1 position?
  • on lines 28 - 30 those two variables don't need to be declared since they are gonna be nothing anyway or are already there...
  • on line 32 you move the character's torso which will make the player die, either move the character - with :MoveTo() or use the Character's PrimaryPart to properly CFrame with Character:SetPrimaryPartCFrame()
  • When you call Check() don't send the player's name send the player Instance

This code should help you:

local Model = "teleporter1b";
local gamepassId = 299858716;

local MPS = game:GetService("MarketplaceService");

local function Check(Player)
	return MPS:PlayerOwnsAsset(Player, gamepassId);
end

script.Parent.Touched:connect(function(Touched)
	local plr = game.Players:GetPlayerFromCharacter(Touched.Parent)
	if plr then
		local Char = Touched.Parent
		local tTo = script.Parent.Parent:FindFirstChild(Model);
		if Check(plr) then
			local location = {x = tTo.Position.x + math.random(-1,1), y = tTo.Position.y + math.random(2,3), z = tTo.Position.z + math.random(-1,1)};
			
			Char:SetPrimaryPartCFrame(Vector3.new(location.x,location.y,location.z), Vector3.new(0,location.y,0))
			script.Parent.Enabled.Value = 0;
			tTo.Enabled.Value = 0;
			wait(3)
			script.Parent.Enabled.Value = 1;
			tTo.Enabled.Value = 1;
		else
			print("Insufficient permissions.");
		end
	else
		print("Could not find teleporter!");
	end
end)

Suggestions:

To make your code easier for others and yourself to read please do follow proper formatting and avoid unnecessary spacing! Also please do indent instead of spacing out your code.

Helpful Links:

http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo http://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame

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