#How would I end a function/return to the top if conditions are met at any point within it?
1 messages · Page 1 of 1 (latest)
local Players = game:GetService("Players")
local started = game.ReplicatedStorage.RoundStarted
local ended = game.ReplicatedStorage.RoundEnded
Players.PlayerAdded:Connect(function(player)
local function round()
local text = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("RoundsTextLabel")
local timer = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TimerTextLabel")
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.CFrame = CFrame.new(game.Workspace.SpawnLocation.Position.X, game.Workspace.SpawnLocation.Position.Y + 3.5, game.Workspace.SpawnLocation.Position.Z)
text.Text = "Waiting for players..."
timer.Visible = false
local playercount = #Players:GetPlayers()
repeat
wait()
until playercount >= 2 or game:GetService("RunService"):IsStudio()
timer.Visible = true
text.Text = "Intermission..."
for i = 20, 0, -1 do
timer.Text = i
task.wait(1)
end
timer.Visible = false
text.Text = "Round started!"
task.wait(2)
timer.Visible = true
humanoidRootPart.CFrame = game.Workspace.RoundSpawnPart.CFrame
text.Text = "Round ongoing..."
started:Fire()
for i = 180, 0, -1 do
timer.Text = i
task.wait(1)
end
ended:Fire()
text.Text = "Round ended!"
task.wait(2)
end
while true do
round()
end
end)
what is this? lua local playercount = #Players:GetPlayers() repeat wait() until playercount >= 2 or game:GetService("RunService"):IsStudio()
waits until the player count is >= 2?
it only happen once
local Players = game:GetService("Players")
local maxPlayers = 2 -- change to whatever
local function checkPlayerAmount()
if #Players:GetPlayers() <= maxPlayers then
-- player amount is less than max players
end
Players.PlayerAdded:Connect(checkPlayerAmount)
Players.PlayerRemoving:Connect(checkPlayerAmount)
i think
this
you will need to know some fundamentals to make this work, i suggest starting here https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
should be alr
i know the fundamentals
split code into functions and variables instead of one long function that cannot be interrupted
kinda like this
reusable
functions
this is a good place to start
you would have playeradded:connect(function(player) ... addplayertoround(player) ... etc ... end)
and in playerremoving removeplayerfromround(player) ... function removeplayerfromround(plr) numplayers -= 1; checkplayercount() end etc
you said you knew the fundamentals? 
uh
that wasn't intended for you to just copy+paste
you will need to know some fundamentals to make this work, i suggest starting here https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
this is scripting-help not free-scripts 
idk how to make it work at any time in the function
Players.PlayerAdded:Connect(function()
if checkPlayerAmount() then -- make the function return true or false
end
end)
another way
because i have to call it manually
to do
you mean you have to put in work to figure out how to write the code? i'd call that manually. yes
you would have to learn how to write the code to do it manually.
local Players = game:GetService("Players")
local maxPlayers = 2 -- change to whatever
local function checkPlayerAmount()
if #Players:GetPlayers() <= maxPlayers then
-- player amount is less than max players
return false
else
return true
end
end
thats a nice way of doing imo
i like making check functions
it makes code look clean
yes it is sign of s1~s2
s1-s2?
how would i stop the top function
yo btw do functions outside of the event so you can use elsewhere
so many docs 😭
but its neccesary
read random docs pages you never know what you might learn https://create.roblox.com/docs/reference/engine/classes/SharedTableRegistry https://create.roblox.com/docs/reference/engine/datatypes/Content https://create.roblox.com/docs/reference/engine/classes/StarterPlayer
uh how do i apply for a scripting rank, like what do i send 😭
like what works
okay ill try find smth
not like 4 scripts each with one function in it
man idk
i've been tryna figure this out for so long
local Players = game:GetService("Players")
local started = game.ReplicatedStorage.RoundStarted
local ended = game.ReplicatedStorage.RoundEnded
Players.PlayerAdded:Connect(function(player)
local function round()
local text = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("RoundsTextLabel")
local timer = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TimerTextLabel")
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.CFrame = CFrame.new(game.Workspace.SpawnLocation.Position.X, game.Workspace.SpawnLocation.Position.Y + 3.5, game.Workspace.SpawnLocation.Position.Z)
text.Text = "Waiting for players..."
timer.Visible = false
local playercount = #Players:GetPlayers()
repeat
wait()
until playercount >= 2 or game:GetService("RunService"):IsStudio()
timer.Visible = true
text.Text = "Intermission..."
for i = 20, 0, -1 do
timer.Text = i
task.wait(1)
end
timer.Visible = false
text.Text = "Round started!"
task.wait(2)
timer.Visible = true
humanoidRootPart.CFrame = game.Workspace.RoundSpawnPart.CFrame
text.Text = "Round ongoing..."
started:Fire()
for i = 180, 0, -1 do
timer.Text = i
task.wait(1)
end
ended:Fire()
text.Text = "Round ended!"
task.wait(2)
end
while true do
round()
end
end)
depends on the modules, if you use them effectively then sure. whole systems that you can show off get more points
dont worry its quite simple just try focusing on how to use events
alright
like
because i have to do return it inside the function but i want it to return whenever it goes under 2
not long enough, apparently https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
my framework would be alright
but other things are happening
framework + show use-case example/working game with it and u will probably get s2
whats the best rank lmao