#How do I make it so my Play button will teleport player to spawn point
137 messages · Page 1 of 1 (latest)
what exactly do you mean by play button?
like gui?
yeah
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
is there a way
I could make it so
the spawn point
is still random?
I got like 5
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?
sure
to make it random use math.random()
wait what exactly are you wanting to make random
yes that would work too
spawn
like the position the players tped to?
OK so ill explain it all
as in which one they are tped to
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
well i have a script but its very inefficient
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
big brain potat
btw just a question but are you a fellow potato?
possibly my long brother
no 😔
:((
YES
i have been a potato from the begenning
this will make it so when i spawn it will be random right
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)
OO
there we go
that should hopefully work although i just wrote it in discord
you can add as much positions as you want to the SpawnVectors table
the positions are the spawn points right
yes
do i have to find each one and copy and paste position then
lol a lot more efficent than mine
just put Vector3.new(Spawn point position goes here)
yes
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
yes
you would make it like this Vector3.new(240.4, 10.205, -139.635)
and put that in the table
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
yes although delete everything after the vector3
oh ok
local SpawnVectors = { Vector3.new(240.4, 10.205, -139.635)} -- 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)
if you want to add more just put a comma then add another position
yes
although its already ended
if it doesnt work ill actually go into studio
and fix it
since i just wrote it in dizzy
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
you keep the two {} like that
ok
just dont touch them and space it out inside of them
ahh dont add that bracket in the middle
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
sure
ok
ill have it done in like 5 min ide say
ok ok
ahhh wait i forgot humanoid root parts use cframes and not positions
rip
k
-- 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
sure
which one
dm