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.
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.
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!
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
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