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

teleport script with use of a screenGUI button?

Asked by 5 years ago

I am trying to make a menu with buttons that teleport the player to different parts of the map, but as of now it only works when teleporting all players instead of the player pressing the button. the location of the script is as follows:

ServerScriptService

some script that copies The GUI within it to the PlayerGui on playerAdded

Gui

Frame

TextButton

the teleport Script

I tried a few varriations of code, but the only one that seems to work (as in, it teleports everyone in the server) is this one:

location = game.Workspace.Spawnpoint
button = script.Parent.Parent.Parent.TextButton
frame = script.Parent.Parent
function onClick()
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.Character then
            local CSpawn = location
            v.Character:MoveTo(CSpawn.Position)
        end
    end
frame.Visible = false
frame.Active = false
button.Text = "Open Menu"
end

script.Parent.MouseButton1Click:connect(onClick)

Anyone know how to make this script so that it works on the player clicking the button but not the rest of the players?

1 answer

Log in to vote
1
Answered by
valchip 789 Moderation Voter
5 years ago
Edited 5 years ago
local part = workspace.tppart
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
     if humanoidrootpart then
        humanoidrootpart.CFrame = CFrame.new(part.CFrame.p)
    end
end)

--//Made by 3chars20

Add this inside a textbutton, local script. At local part locate the part you want to teleport the player to. Do not change the local plr thingy because it locates the player. The other line is an event which is activated when you click the button. At humanoid root part we locate the humanoid root part. Then we check if the player has a humanoid root part, if it does then it teleports the players to the part. You are probably a beginner so tried explaining you what happens in the script.

0
thanks that seems to do the trick... thought I already tried this variant.... not a true beginner, but some things I did not explore yet Rubenske1 89 — 5y
0
If you accept this answer, please mark it as so. Sir_Melio 221 — 5y
Ad

Answer this question