TeleportService Script not Teleporting

Hello! So I wanted to script something that teleports you to another place. For some reason it’s not working. No errors, just nothing. I did test it in a real game, not in Studio.
Script:

local player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local SurfaceGui = script.Parent
local TextButton = SurfaceGui.TextButton
local placeId = 5160756942
local defaultText = [[Click to get teleported to the Training Center.
Note that Trainings are not getting hosted all the time.]]

local ranks = {
	["Guest"] = 1;
	["Trainee"] = 2;
	["Barista"] = 3;
	["Head Barista"] = 4;
	["Supervisor"] = 5;
	["Manager"] = 6;
	["Chief Executive Officer"] = 7;
	["Developer"] = 8;
	["President"] = 9;
	["Founder"] = 10;
	
}


TextButton.MouseClick:Connect(function()
	--Teleport him to the TC
	--But first check his rank
	local role = player:GetRoleInGroup(6615557)
	local rank = ranks[role]
	if rank >= 2 then
		TeleportService:Teleport(placeId, player)
	else
		TextButton.Text = "You have to be a Trainee or above to be able to get teleported to the Training Center."
		wait(3)
		TextButton.Text = defaultText
	end
end)

Is there any output, or anything?

1 Like

If im right, its in a local script and you dont need to add the player to the Teleport line. Just the place id.

1 Like

Nope, there is no output.

30chars

If it doesn’t work on a local script use a remote event.

1 Like

Yep, but you can. I’ve removed the player parameter so it’s default now, still not working. I will try it with a Remote Event.
https://gyazo.com/f5c07dccb7aa57c0f717ccf3bf194ffa

I can see a table of ranks defined with numbers, but I don’t see where the script links those ranks to the player. You are checking the ranks against a table, but the table isn’t linked to the player so the script doesn’t know which rank to use.

EDIT: nvm, I overlooked that part

1 Like

I’ve tried it with a Remote Event, still not working.
Script:

--Local Script
local player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local SurfaceGui = script.Parent
local TextButton = SurfaceGui.TextButton
local defaultText = [[Click to get teleported to the Training Center.
Note that Trainings are not getting hosted all the time.]]
local RS = game:GetService("ReplicatedStorage")
local Teleport = RS.Remotes.Teleport

local ranks = {
	["Guest"] = 1;
	["Trainee"] = 2;
	["Barista"] = 3;
	["Head Barista"] = 4;
	["Supervisor"] = 5;
	["Manager"] = 6;
	["Chief Executive Officer"] = 7;
	["Developer"] = 8;
	["President"] = 9;
	["Founder"] = 10;
	
}


TextButton.MouseClick:Connect(function()
	--Teleport him to the TC
	--But first check his rank
	local role = player:GetRoleInGroup(6615557)
	local rank = ranks[role]
	if rank >= 2 then
		--Fire a Remote Event
		Teleport:FireServer()
	else
		TextButton.Text = "You have to be a Trainee or above to be able to get teleported to the Training Center."
		wait(3)
		TextButton.Text = defaultText
	end
end)
--Server Script
local RS = game:GetService("ReplicatedStorage")
local Teleport = RS.Remotes.Teleport
local TeleportService = game:GetService("TeleportService")
local placeId = 5160756942

Teleport.OnServerEvent:Connect(function(player)
	TeleportService:Teleport(placeId, player)
end)
1 Like

I’ve found the issue. I did MouseClick instead of MouseButton1Click, there is no MouseClick event for TextButton.

1 Like

I think I’ve figured it out. From what I know about group ranks, don’t you usually get the ranks by checking a number. For example the ‘owner’ rank = 255 in the group.

2 Likes

It’s still not working… ;-;

30chars

Found an example.

game.Players.PlayerAdded:Connect(function(Player))
if player:GetRankInGroup(group id here I think) == 255 then —— 255 is owner
print(“player is owner of the group”)
end

2 Likes

GetRoleInGroup returns a StringValue, for example Customer. My table checks the StringValue and replaces it with a number (1-10). I can check his rank with these numbers now.

1 Like

ok, I’ve not used that method before because I’m new to scripting, try using a print statement to print the player’s role. This will help see if it’s working as it should be.

2 Likes

Alright, that’s weird. Looks like the event is not even getting fired.
Script:

local player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local SurfaceGui = script.Parent
local TextButton = SurfaceGui.TextButton
local TeleportService = game:GetService("TeleportService")
local defaultText = [[Click to get teleported to the Training Center.
Note that Trainings are not getting hosted all the time.]]

local ranks = {
	["Guest"] = 1;
	["Trainee"] = 2;
	["Barista"] = 3;
	["Head Barista"] = 4;
	["Supervisor"] = 5;
	["Manager"] = 6;
	["Chief Executive Officer"] = 7;
	["Developer"] = 8;
	["President"] = 9;
	["Founder"] = 10;
	
}


TextButton.MouseButton1Click:Connect(function()
	print("Click")
	--Teleport him to the TC
	--But first check his rank
	local role = player:GetRoleInGroup(6615557)
	local rank = ranks[role]
	print(rank)
	if rank >= 2 then
		print("Yes")
		--Fire a Remote Event
		TeleportService:Teleport(5160756942)
	else
		print("Else")
		TextButton.Text = "You have to be a Trainee or above to be able to get teleported to the Training Center."
		wait(3)
		TextButton.Text = defaultText
	end
end)

No output.

The default text variable has [[]] instead of “”. Why is that?

1 Like

It’s a multi-line string because it would be too long.

1 Like

Ok, but there is a property in Text Buttons which makes it go to the next line when enabled

1 Like

Removed the Multi-Line string, still not working. :confused:

1 Like

(Replaced it with local defaultText = "Click to get teleported to the Training Center.Note that Trainings are not getting hosted all the time.")

1 Like