✓ Accepted answer
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
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)
3 comments
Not a request site, attempt this yourself and we'll help you on improving your code.
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.
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.