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?

2 comments
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
If you accept this answer, please mark it as so.