How to make a button that spawns the player

I want to make a button that when clicked, would spawn the player into the map. The player would not spawn into the map until he clicks the button. How do I make it?

I cant find any tutorials on Youtube about this.
When I made the script it doesn’t work.
Any help is appreciated. :smiley:

You can have it so all the players are in a waiting room, and when the player presses the button it teleports the player into the correct position in the game.

2 Likes

But I dont want the players to spawn in one position only I need them to spawn in various locations around the map.

Wouldn’t you just Utilize :MoveTo()?
if you just want them to teleport somewhere, then just do:
(btw this is in the context of a proximityprompt)

local location = --location goes here
script.Parent.Triggered:Connect(function(player)
player.Character:MoveTo(location)
end)

Put a folder named “SpawnLocations” in workspace and put parts in (Part1,Part2,Part3…)

then , if your button is a GUI button , put a Local script in:

 script.Parent.MouseButton1Clicked:Connect(function())
local MaxPart = 3 -- How many Spawn locations you have.
local HRP = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
HRP.CFrame = game.Workspace.SpawnLocations["Part"..math.random(1,MaxPart).CFrame
end)

else , if your button is a ClickDetector , put a local script in:

 script.Parent.ClickDetector.MouseClick:Connect(function())
local MaxPart = 3 -- How many Spawn locations you have.
local HRP = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
HRP.CFrame = game.Workspace.SpawnLocations["Part"..math.random(1,MaxPart).CFrame
end)

I hope it’ll works , I didn’t test it so , tell me if it doesn’t work! :slight_smile:

make a room somewhere with a “Spawn Location” in.

image

image

image

Thanks for all the replies. I am having my examinations so I can’t test them. I will get to you when my examination ends. Thanks for the replies everyone :slight_smile:

Thanks! I will try them out now since i have a bit of free time

Dose not work :frowning: The script has errors in it.

what is the error? (press f9 while testing the game in roblox studio)

I did. It says = expected identifier when parsing expression, got ‘)’

Sorry , my script was wrong but it should works now ,
here is the file , you can only take the button if you want. Button_Teleport.rbxl (33.6 KB)

Thanks man. It worked. Very Cool :smiley:

you can even replace local MaxPart = 3 by
local MaxPart = #game.Workspace.SpawnLocations:GetChildren()
so you don’t have to change the script every time you add a part.

I know this topic was solved already but a very simple way you could do this is by turning off AutoPlayerLoad (It might be called something else but I don’t remember what it’s called but it’s similar to that.) And then in said button GUI you make a script that says

Script.Parent.MouseButton1Click:Connect(function()
    Game.Players.LocalPlayer:LoadCharacter()
end)

Then just have SpawnLocation instances and the player will spawn randomly on one of these

If you want them to spawn on a specific spawn point you can just set the players humanoid root part’s CFrame to the spawn location’s CFrame.

4 Likes