How to fix this teleport script?

  1. What do you want to achieve?
    A teleport system for admins

  2. What is the issue?
    My script does not work.

localValue and playerValue are player objects.

local localValue = script.Parent.Parent.localValue.Value
local playerValue = script.Parent.Parent.playerValue.Value

local function TeleportTo()
	localValue.Character.Torso.CFrame = playerValue.Character.Torso.CFrame
end

local function Bring()
	playerValue.Character.Torso.CFrame = localValue.Character.Torso.CFrame
end

script.Parent.To.MouseButton1Down:connect(TeleportTo)
script.Parent.Bring.MouseButton1Click:Connect(Bring)


How the UI looks

1 Like

You need to refer to the actual player objects. Do this by finding it in game.Players. It will return nil if the player is not in the game.

local localValue = game.Players:FindFirstChild(script.Parent.Parent.localValue.Value)
local playerValue = game.Players:FindFirstChild(script.Parent.Parent.playerValue.Value)

But both ObjectValues contain a player object.
(It doesn’t work with your solution)
As soon as a player leaves, the entire Frame will be deleted. The Frame is just a part from a playerlist.

localValue is the LocalPlayer (that’s all the LocalScript inside of it does).
And the playerValue is the player that joined (every player has its own duplicated frame).

You cant teleport players on the client. I recommend using a Remote Event.

Also, what the hell is player value? You should do:

local player = game.Players.LocalPlayer

It’s a script and not a LocalScript

Then it would just not work at all.

Why? It’s a script that knows both the LocalPlayer (via playerValue) and the other player (playerValue). And then the script changed the positions of the torsos.
But it does not work currently and I don’t know why

First of all, you cant use scripts to trigger a button, only a local one. Second of all the player value is a thing that doesnt exist. Try following this tutorial. HOW TO CREATE A TELEPORTER GUI | Roblox Studio - YouTube

You can use scripts that run functions after a button is pressed. And also playerValue is getting the player object from the LocalScript inside of it.
Also, the video does not show how to teleport a player to the player, who is clicking the button.

Bruh, I thought you know at least basic scripting.

I do know scripting (except for very advanced situations, e.g. modules). But I have trouble solving this problem. Maybe you can give me example code that might solve my problem.

Try running your script inside a LocalScript so you can actually detect the events. I think users have network ownership over their character so they will be able to move themselves just not other admins to them.

Why is your script disabled? That might be the actual issue.

It’s a player list and the handler enables the script as soon as the frame gets duplicated and all the informations are getting filled up.
Basically, another script enables it.

First make a local script in the teleport frame. After that put a remote event ( DO NOT RENAME IT )
in the teleport frame. Then put this code in the local script:

local localValue = script.Parent.Parent.localValue.Value
local playerValue = script.Parent.Parent.playerValue.Value

local function TeleportTo()
	script.Parent.RemoteEvent:FireServer(localValue.Character.Torso.CFrame,playerValue.Character.Torso.CFrame)
end

local function Bring()
	script.Parent.RemoteEvent:FireServer(playerValue.Character.Torso.CFrame,localValue.Character.Torso.CFrame)
end

script.Parent.To.MouseButton1Down:connect(TeleportTo)
script.Parent.Bring.MouseButton1Click:Connect(Bring)

Then in the normal script put this:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(v, t)
    v = t
end)
1 Like

I’m going to try that tomorrow because I am currently not on my PC! Thank you!

You are very welcome. If it doesn’t work I can try scripting it for you.

1 Like

It sadly does not work either. (I think, the client can not access the character)