I’m very new to coding and trying to make a game based around the Hyperlaser gun. I’m trying to make a rounds system but I can’t find a script that works… Can anyone help me out? (This is my first post)
Hi there, this is my first post too
One way you could do it is to put a script inside of serverscriptservice (so that it runs on everybody’s screens) and have the script look something like this:
ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')
while true do
--Intermission
local Countdown = 10 --ten second intermission, make this as long as you want
repeat wait(1)
Countdown = Countdown -1
Status.Value = 'Intermission : '..Countdown
until Countdown <= 0
--Choose the map
Status.Value = 'Choosing Map.'
local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
local Spawns = ChosenMap:FindFirstChild("Spawns"):GetChildren()
local RandomSpawn = Spawns[math.random(1, #Spawns)]
wait (5) -- little pause, make this as long as you want
ChosenMap.Parent = workspace
Status.Value = 'Map chosen, teleporting players.'
wait (2) --little pause, make this as long as you want
--teleport the players
for _, Player in pairs(Players:GetChildren()) do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
end
end
Countdown = --Starting Round In, make this as long as you want
repeat wait(1)
Countdown = Countdown -1
Status.Value ='Round ends in : ' ..Countdown
until Countdown <= 0
Countdown = 12 --Game Time , ten seconds, make this as long as you want
repeat wait(1)
Countdown = Countdown -1
Status.Value ='Ingame : ' ..Countdown
until Countdown >= 0
--Kill the players
for _, Player in pairs(Players:GetChildren()) do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.Humanoid:TakeDamage(2000)
end
end
ChosenMap:Destroy()
Status.Value = 'Round Ended, waiting for new game.'
wait (4) --little pause, make this as long as you want.
end
This is all put inside a while true do loop because then it will go on forever so that when a round ends another one with start. Also, the “status” is just the GUI (what the player sees on the screen (e.g. timer)). Along with this code being in a script in serverscriptservice you would need to add maps into serverstorage and if you want, a gui into starter gui (that is the status).
Hope this helped, let me know if you need any help with it, otherwise, I’m sure there are heaps on tutorials on this.
That’s uh… pretty complex to answer in a forum post (which really depends on how your game will work), and it’ll be even harder to explain since I don’t know how code-fluent you are and I don’t want to tell you how to do stuff you don’t fully understand yet. How much coding do you know? Do you know what events are and such?
I highly recommend taking the time to go through this gameplay scripting tutorial: Gameplay Scripting Curriculum | Documentation - Roblox Creator Hub
The tutorial is a walk-through of implementing this uncopylocked laser tag place
In particular, check out section 3 on implementing rounds
But the rest of the tutorial is helpful to help contextualize that part.
The idea is to have an infinite loop that iterates through intermission and game time. We need a value in rep storage that’s value we will be updating with the loop. But we need to change any associated gui on the client for the players to see it.
local status : StringValue = game.ReplicatedStorage.Status
local intermissiontime = 10
local gametime = 30
function Timer()
while true do
for i = intermissiontime,0,-1 do
Status.Value == “Intermission : “..i..” seconds left!”
task.wait(1)
end
— code here to start round
for i = gametime,0,-1 do
Status.Value == “Game: “..i..” seconds left!”
task.wait(1)
end
end
end
spawn(Timer)
Then in the local script
local displaylabel = —Text label displaying the status here
local status = game.ReplicatedStorage.Status
status.Changed:Connect(function()
displaylabel.Text = status.Value
end)
New to roblox studio? Me too. A coincidence is that not long ago (like, today) I made a round and map system using an official tutorial book. I recommend purchasing these 2 books:
- Coding with Roblox Lua in 24 hours
- Roblox Game Development in 24 hours
They’re both official. They are divided in hours (24 each, a total of 48 hours) and each hour covers something about Studio. I recommend starting at the first one (Coding with Roblox Lua in 24 hours). At hour 12 of the first one, you can find pretty helpful tips about round engines and map selections! (I myself was very sad when I deleted the scripts to move on to the next hour)
EDIT: Hour 18 (of the first book too) also covers some nice scripting about game loops (rounds etc.) which I think that is also what you want
there are many ways to make it the way i prefer is using recursive functions to make the main loop
and make a module with all the functions that i will need and use them in the main function
this is just an example and this maynot be the best way to make it
local function MainLoop()
if PlayerCount > 1 then
print("RoundStarted")
StartGame() -- replace with your logic
print("The Round Ends In 60 Seconds")
task.wait(60)
EndRound() -- ends the round
task.wait(15) -- some time to make players stay in lobby for some time
MainLoop() -- we start the round again
else
MainLoop() -- will keep firing until there are 2+ players in the server
print("2 Players Needed At Least To Start")
end
end
MainLoop()
and if you want the player`s gui to update you can check DrMystery’s post
Thanks, but where do I put the scripts?
I stated in my post; first block of code in a server script in SSS and the second one in a local script under your text label in startergui