2 Errors in my script

Hello Developers! I am trying to make a round script, but their is an error that says "Error:(12,5) Expected ‘)’ (to close '('at line 11), got ‘wait’. Also, I want it so that it selects a random map and teleports all player there. Thanks!

maps = {game.Lighting.Map1, game.Lighting.Map2, game.Lighting.Map3, game.Lighting.Map4}

--Server script under ServerScriptService
local event = game:GetService("ReplicatedStorage"):WaitForChild("ServerMessage")

--Game logic that starts intermission & stuff, but this is just a demo

while true do
game.Workspace.Sound1:Play()
for i = 30, 1, -1 do
	event:FireAllClients("A new round will begin in " .. i .. "s"
    wait(1)
if i == 1 then
   game.Workspace.Sound1:Stop()
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Choosing map..."
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Choosing map.."
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Choosing map."
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Map: ".. math.random(1, #maps).." has been chosen"
end
end
end

you had to put an and at line 11.

That doesn’t work unfortunately

move an end from the bottom to after the wait(1)

event:FireAllClients("A new round will begin in "  .. i .. "s")
wait(1)
end 

Also event:FireAllClients("A new round will begin in " … i … “s”
is missing a parenthese at the end.

What about the random map choosing? I’m pretty sure you use math.random correct? (Also, the code for some reason stops after the game.Workspace.Sound1:Stop() part.)

ok two things:
first, does the error still pop up?
second, to test if your map voting system work just look at the text a few times in different games. press play a few times. If the map same map pops up all the time then you are using math.random wrong. About the teleportation, do you want it to teleport to a different game or within the same game?
sorry if I sound a bit rude here.

If you wanted to randomize a map, i suggest that you use a table to do so. Like such:

local maps = {"Forest","City","House"}
local chosenMap = maps[math.random(1,#maps)] 
print(chosenMap)

Line 11:
You require a ) to close the method else an error will occur.

Incorrect way to change someones screen:
By using game.StarterGui you are changing the master copy and not the user copy. Instead you might want to do event:FireAllClients() again to set the text.

This is why the code “randomly stops” as you suggested, you have only changed the server copy and as such if a new client joined they would see this change themselves whereas all active players would not.

Randomization issue:
By doing math.random(1, #maps) you will only display the number and not the map itself. Switch to:
maps[math.random(1, #maps)].Name. Another issue you will encounter as well is trying to get the selection after, store the result of maps[math.random(1, #maps)] as something like selected_map that way you can then call the map by doing selected_map.Name and also load the map in at the same time.

3 Likes

When I try to fire all clients again, its shows an error in the output

1 Like

I found something rather odd. The Choosing map part and all the code below, show on the server, but not the client. Why?

Are you talking about the Guis? Why are you changing the StarterGui and not the PlayerGui?

How do you change the player Gui? Is it game.Players.PlayerGui ?

What are you trying to do here? Make the parts that change the Gui every second show up for the players? The StarterGui is only the place that the Guis are clones into the player. The player Gui is what the player sees.

Yeah (30 charrrrrrrrsssssssssssss)

1 Like

I would suggest you to do something else.

  1. Create a string value in the Replicated Storage.
  2. In the intermission text label, create a local script like this:
local value = game:GetService("RepliactedStorage").StringValue --Your Value name goes here.

script.Parent.Text = value.Value

value:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = value.Value
end)

Step 3. change the value in your intermission script instead of changing the Text in the StarterGui.
That way, every time that you changed the value to your intermission text, the function will run, and that will change the TextLabel’s text to the String Value’s Value.

Oh my, we should just talk about your script in general…

maps = {game.Lighting.Map1, game.Lighting.Map2, game.Lighting.Map3, game.Lighting.Map4}

This is very messy. Set a folder under ReplicatedStorage or ServerStorage, but for christ’s sake please don’t use Lighting like everybody did in 2013 :joy:

In addition, you are using a preset table AND using a global variable. Do local beforehand, and make a folder of maps and use GetChildren to get the maps.

for i = 30, 1, -1 do
	event:FireAllClients("A new round will begin in " .. i .. "s"
    wait(1)
if i == 1 then

Why did you do this? You could just do the for loop, then do the game logic.

Do

for i = 30, 1, -1 do
	event:FireAllClients("A new round will begin in " .. i .. "s"
    wait(1)
end

--// Game stuff here
game.StarterGui.Intermission.TextLabel.Text = "Choosing map..."
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Choosing map.."
   wait(1)
   game.StarterGui.Intermission.TextLabel.Text = "Choosing map."
   wait(1)

Couple things wrong with this. One: setting text in starterGui won’t change the text in a player’s UI. Two: you don’t use any sort of for loop to reduce redundant code. Three: don’t ever create false loading times. Let the player’s get in and out of matches quickly.

Overall, I think you may want to follow some more tutorials on Roblox Developer Hub or CK-Studio+, because this is super messy and is considered the basics of Roblox.

I hope I didn’t come across as mean, however (it’s hard to show tone with text). I want to make sure my feedback helps you out and and you learn from the mistakes you made :slight_smile:

Ok thanks for the feedback (I’m actual new to scripting, so this taught me a lot)

1 Like