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

How to tp a random player after clicking a textbutton?

Asked by 4 years ago

Ive tried all i have to my knowledge but it doesnt work pls help

2 answers

Log in to vote
0
Answered by 4 years ago

place this in a local script as a child of the text button.

this should work, you can only get click detection of a gui if the script is a child of it, and you have to use the humanoid root part or torso of the player to teleport them.

local teleportPart = workspace:WaitForChild("TeleportPart")
local textButton = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local torso = character:FindFirstChild("Torso")

textButton.OnMouseClick:Connect(function()
    if humanoidRootPart then
        humanoidRootPart.CFrame = CFrame.new(teleportPart.CFrame)
    end

    if torso then
        humanoidRootPart.CFrame = CFrame.new(teleportPart.CFrame)
    end
end)
0
oh and make a part in the workspace called TeleportPart Code1400 75 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local teleportPlace = Vector3.new(0,0,0) 
local text = script.Parent
local randomplayer = math.random(1,#game.Players:GetPlayers)
local randomplrHRP = randomplayer:WaitForChild("HumanoidRootPart")
debounce = false

if text.MouseButton1Click then
    debounce = true
    print("The random player is...".. randomplayer "!")
    print("Teleporting".. randomplayer .."...")
    if randomplayer then
        randomplrHRP.Position = teleportPlace
        print("Success teleported".. randomplayer.. "to the teleportPlace's position!")
    else
        error("randomplayer was a nil value.")
    end
    debounce = false
end

Btw, make the game as R15.

Second, make the teleportPlace's position to the position that you want!

~~ How this script works ~~

We don't need to discuss about what we localed cause its useless to know about though.

if text.MouseButton1Click then

this makes the code that sandwiched inside if text.MouseButton1Click then fires whenever people click the button.

Btw, if the print code is bugging, just mark them as note or delete them lol... They're useless and do nothing else prints what they did in the output.

Later, if we localed the randomplayer, and then pressed the button, they will sensor about are the randomplayer is in the game, if it doesn't, it put out an error.

In a nutshell, pressed the button, get randomplayer and makes the randomplayer's humanoid root part to the teleportPlace's position!

If you don't know how to make the game to R15, see the below!

And if this helped you, mark this as the answer, if doesn't help or need more explains, comment below down too! thanks :)

Go to my video to see how to make the game r15! Btw subscribe pls

Answer this question