Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a gui that lets u tp to a player?

Asked by 4 years ago
Edited 4 years ago

im trying to make a admin gui pls help

here is my code:

local plrn = script.Parent.Parent.PLRN.Text
local plr1 = game.Players.LocalPlayer.Character
local plr2 = game.Workspace:FindFirstChild(plrn)
local btn = script.Parent

btn.MouseButton1Down:Connect(function()
    plr1.HumanoidRootPart.CFrame = plr2.HumanoidRootPart.CFrame * CFrame.new(0,2,0)
end)
0
Not a request site, attempt this yourself and we'll help you on improving your code. killerbrenden 1537 — 4y
1
True, this isn't a request site, but to let you know, to teleport people, you want to teleport your player's humanoidrootpart CFrame to the other player's humanoidrootpart cframe. Qariter 110 — 4y
1
code was edited here a few minutes after you asked for it. It might just might be a better idea to check the post again after 30 minutes-2 hours before starting a claim on it. moo1210 587 — 4y

1 answer

Log in to vote
1
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

Don't save that variable "plrn" with a textbutton.Text property (plrn = script.Parent.Parent.PLRN.Text), as it will save the current string, and if u later write on the textbox, the variable wont change. Instead, you have to save the textbox object on the variable and call the text property when you want to use it:

plrn = script.Parent.Parent.PLRN
print(plrn.Text)

plr2 variable isnt set correctly, as it might find a game model instead of a player. Instead of finding a model inside the workspace, try finding a player inside game.Players and then finding its character, making sure to check if they exist:

plr2 = game.Players:findFirstChild(plrn.Text)
if plr2 and plr2.Character then
    --teleport player here
end

You will want to set and check plr2 just after clicking the button, so it finds a new player with the text everytime you click on the button. You are currently trying to find a player as soon as the script run, and that player will never change no matter what u type on that textbox. Here is how it should be like:

btn.MouseButton1Down:Connect(function()
    plr2 = game.Players:findFirstChild(plrn.Text)
    if plr2 and plr2.Character then
        plr1.HumanoidRootPart.CFrame = plr2.Character.HumanoidRootPart.CFrame * CFrame.new(0,2,0)
    end
end)
Ad

Answer this question