How to get a player in a serverscript for teleportation

  1. What do you want to achieve? Keep it simple and clear!
    I need to get the player in a serverscript so i can teleport the player
    using teleportService when he clicks on a gui
  2. What is the issue? Include screenshots / videos if possible!
    This is the script that creates the button
local worlds = script.Parent.Parent.Worlds
local button = script.Parent
local Value = script.Parent.Parent.Configuration.Value
local maxWorlds = false
local World = nil
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	if maxWorlds == false then 
		World = script.Parent.Parent.Parent.Replicated.World:Clone()
		World.Parent = worlds
		World.Name = "World" .. Value.Value
		World.Text = "World" .. Value.Value
		World.Visible = true
		World.TextScaled = true
		Value.Value += 1
		end
	if Value.Value == 6 then
		maxWorlds = true
		button.Text =  "Max Worlds Reached"
	end
end)

this is the script that teleport the player

script.Parent.MouseButton1Click:Connect(function()
	local player = script.Parent.Parent.Parent.Parent.Parent.Parent
	local teleportService = game:GetService("TeleportService")
	teleportService:TeleportAsync(15333331947, {player})
end)
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
--> Use LocalPlayer
local Player = game.Players.LocalPlayer

Use LocalScripts when dealing with UI

-- Should be a LocalScript not a ServerScript
local TPS = game:GetService("TeleportSerivce")
local Player = game.Players.LocalPlayer -- Yourself

script.Parent.MouseButton1Click:Connect(function()
  TPS:TeleportAsync(15333331947, {Player})
end)
1 Like

You can’t teleport with a local script, i have tried