Still have questions? Join our Discord server and get real time help.
0

# Why can't my character teleport?

Edited 7 months ago

I am making an admin script that when a certain button is pressed, it will teleport the person who's name is typed in one text box to the person who's name is typed in another text box. For some reason, it isn't working. Local script in StarterGUI

local Event = game.ReplicatedStorage.Folder:WaitForChild("AT")

script.Parent.MouseButton1Click:Connect(function() --When button pressed
local player = script.Parent.Parent.Player.Text --Player being teleported to
local target = script.Parent.Parent.Target.Text --Player whos being teleported
if game.Players:FindFirstChild(player) and game.Players:FindFirstChild(target) then
Event:FireServer(player,target)
end
wait(1)
script.Parent.Parent.Target.Visible = true
script.Parent.Parent.Target.Text = "Person who's being teleported"
end)


Server script in workspace

local Admins = {"DominousSyndicate"}

local result = false

for i, v in pairs(Admins) do
if player.Name == v then
result = true
end
end
return result
end

if game.Players:FindFirstChild(player1) then

local targetplayer = game.Players:FindFirstChild(player1)
local target = game.Players:FindFirstChild(target)
target.Character.Humanoid.Jump = true
target.Character:MoveTo(player.Character.HumanoidRootPart.CFrame)

end
end
end)

0
It looks like your 'Admins' thing is in a comment tictac67 58 — 7mo

0

### It doesn't work because the argument to MoveTo is a Vector3 value, not a CFrame value. But you should not be using this, use SetPrimaryPartCFrame instead. MoveTo can cause weird behaviour such as teleporting to the sky, and because Vector3 does its best to prevent clipping through BaseParts, it may do the teleporting to the sky. And teleporting the player smack in the HumanoidRootPart can get them stuck, so I'd recommend a little distance between the characters.

--[[Since this is an admin script, its only natural that it would have a whitelist]]--

local function CheckIfAdmin(player) -- use more local functions
local result = false

for i, v in pairs(Admins) do
if player.Name == v then
result = true
end
end
return result
end

if game.Players:FindFirstChild(player1) then

local targetplayer = game.Players:FindFirstChild(player1)
local target = game.Players:FindFirstChild(target)
target.Character.Humanoid.Jump = true
target.Character:SetPrimaryPartCFrame(
player.Character:GetPrimaryPartCFrame() + Vector3.new(0, 0, 5)
-- teleport the player just 5 studs behind them
)

end
end
end)


0
What is MoveTo? I love CFrame and all, but I have not yet encountered that... greenhamster1 107 — 7mo
0
It did not work DominousSyndicate 41 — 7mo