Ad
Log in to vote
0

Why can't my character teleport?

Asked by 10 days ago
Edited 10 days 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"}

function CheckIfAdmin(player)
    local result = false

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

game.ReplicatedStorage.Folder.AD.OnServerEvent:Connect(function(player,player1,target)
    if game.Players:FindFirstChild(player1) then
        local isAdmin = CheckIfAdmin(player)

        if isAdmin 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 63 — 10d

1 answer

Log in to vote
0
Answered by
incapaz 5465 Moderation Voter
10 days ago

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 Admins = {"DominousSyndicate"}

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

game.ReplicatedStorage.Folder.AD.OnServerEvent:Connect(function(player,player1,target)
    if game.Players:FindFirstChild(player1) then
        local isAdmin = CheckIfAdmin(player)

        if isAdmin 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 86 — 10d
0
It did not work DominousSyndicate 24 — 10d
Ad

Answer this question