#How do I make it so my Play button will teleport player to spawn point

137 messages · Page 1 of 1 (latest)

white wharf
#

How do I make it so when the player clicks a play button they will get teleported to a spawn point pls help this has taken me 1 week i just cant find a way to do it plsss

polar sail
#

like gui?

white wharf
#

yeah

dim cedar
#
local spawnPos = workspace.SpawnPoint.Position
local button = script.Parent

button.Activated:Connect(function()
  game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Position = spawnPos
  button.Visible = false
end)

here SpawnPoint is the spawnpoint part and button is the play button

#

^ that would work

white wharf
#

is there a way

#

I could make it so

#

the spawn point

#

is still random?

#

I got like 5

dim cedar
#

yes that will make it random by default

#

oh wait

#

nvm

#

it wont

#

but you can kill the player

#

making it random

#

is that okay?

white wharf
#

sure

polar sail
#

to make it random use math.random()

white wharf
#

as long as theres no oof sound

#

lol

polar sail
#

wait what exactly are you wanting to make random

dim cedar
polar sail
white wharf
dim cedar
#

as in which one they are tped to

white wharf
#

so rn

#

I have a local script inside the play button gui

#

and I want to make it so when I click play

#

it teleports me to a random spawn point

dim cedar
#

well i have a script but its very inefficient

white wharf
#

ill take anything at this point

#

this had made me suffer

#

for almost 2 weeks

dim cedar
#
local rnd = Random.new():NextInteger(1,5)

button.Activated:Connect(function()
  if rnd == 1 then
    --tp1
  elseif rnd == 2 then
    --tp2
#

and continue

#

OOPS nvm

#

lemme fix

white wharf
#

big brain potat

#

btw just a question but are you a fellow potato?

#

possibly my long brother

dim cedar
white wharf
white wharf
dim cedar
#

i have been a potato from the begenning

white wharf
dim cedar
#

yes but i think @polar sail prob has somethig better

#

hes been typing an essay

white wharf
#

hes been typing

#

solid 12 minutes

polar sail
#
local SpawnVectors = {spawn position 1, spawn position 2, spawn position 3} -- Make those positions actual positions like for example vector3.new(5, 5, 5)

local ChosenSpawnvector = math.random(1, #SpawnVectors)

local Players = game:GetService(Players)

Button.Activated:connect(function())
    Players.LocalPlayer.Character:FindFirstChild("HumanoindRootPart").Position = Spawnvectors[ChosenSpawnvector]
end)

white wharf
#

OO

dim cedar
#

there we go

polar sail
#

that should hopefully work although i just wrote it in discord

#

you can add as much positions as you want to the SpawnVectors table

white wharf
polar sail
white wharf
dim cedar
#

lol a lot more efficent than mine

polar sail
#

just put Vector3.new(Spawn point position goes here)

polar sail
#

although if you wanted to you could randomly generate the position by getting the max x and max z of the map or how big it is

white wharf
#

240.4, 10.205, -139.635

#

like this?

polar sail
#

yes

white wharf
#

ok

#

origin or c frame position

#

btw

#

oh they same

#

nvm

polar sail
#

and put that in the table

white wharf
#

local SpawnVectors = { Vector3.new(240.4, 10.205, -139.635), spawn position 2, spawn position 3} -- Make those positions actual positions like for example vector3.new(5, 5, 5)

local ChosenSpawnvector = math.random(1, #SpawnVectors)

local Players = game:GetService(Players)

Button.Activated:connect(function())
Players.LocalPlayer.Character:FindFirstChild("HumanoindRootPart").Position = Spawnvectors[ChosenSpawnvector]
end)

#

so like that

polar sail
#

yes although delete everything after the vector3

white wharf
#

oh ok

polar sail
#

if you want to add more just put a comma then add another position

white wharf
#

what if i want to add more

#

ok

#

ok

#

do i end it

#

with } this

polar sail
#

yes

#

although its already ended

#

if it doesnt work ill actually go into studio

#

and fix it

#

since i just wrote it in dizzy

white wharf
#

ok so

#

{ Vector3.new(240.4, 10.205, -139.635)}, bla bla or { Vector3.new(240.4, 10.205, -139.635), bla bla }

#

do i extend the end

#

or end it

polar sail
#

you keep the two {} like that

white wharf
#

ok

polar sail
#

just dont touch them and space it out inside of them

polar sail
white wharf
#

oh

#

the

#

(

polar sail
#

nonono

#

its right there

white wharf
#

can u

#

do it

#

im dumb

#

183.55, 10.185, 100.705

#

185.05, 10.135, 100.705

#

63.536, 1.025, -21.739

#

335.58, 36.495, -124.535

polar sail
#

sure

white wharf
#

thats all my positions

#

240.4, 10.205, -139.635

polar sail
#

kk

#

im bug fixing rn since it had a few errors

white wharf
#

ok

polar sail
#

ill have it done in like 5 min ide say

white wharf
#

ok ok

polar sail
#

ahhh wait i forgot humanoid root parts use cframes and not positions

white wharf
#

rip

polar sail
#

ill redo it

#

alright i got something working im just going to add your positions nows

white wharf
#

k

polar sail
#
-- Services
local Players = game:GetService("Players")

-- UI Varibles
local Button = script.Parent

-- Player Varibles
local Player = Players.LocalPlayer
local Character = Player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

-- Button Function
Button.Activated:connect(function()
    -- Randomizing Positions
    local SpawnVectors = {CFrame.new(183.55, 10.185, 100.705), CFrame.new(185.05, 10.135, 100.705), CFrame.new(63.536, 1.025, -21.739), CFrame.new(335.58, 36.495, -124.535), CFrame.new(240.4, 10.205, -139.635)}
    local ChosenSpawnVector = math.random(1, #SpawnVectors)
    
    -- Setting Character Position
    HumanoidRootPart.CFrame = SpawnVectors[ChosenSpawnVector]
end)

put this in a local script under the button

#

i also reorginized and added some notes to help you understand where everything is

white wharf
#

ok lemme try it

#

when i click

#

nothing happens

#

u want me to share screen

polar sail
#

sure

white wharf
#

join vc

#

@polar sail

polar sail
#

which one

white wharf
#

dm