Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Minigame script breaks when I put in the script for the second map, any ideas?

So I'm really new to scripting and am trying to make a simple minigame to kickstart me. I have 2 maps, and when I keep out the script for the 2nd map it works fine. However, when I put in the script for the second map, the entire script breaks and I don't know what the problem is. Hopefully this isn't too long for help.

m = Instance.new('Message', workspace)
h = Instance.new('Hint', workspace)
local sword = game.Lighting.ClassicSword:Clone()
num = math.random(1,2)
map = game.Lighting.SF:Clone()
map2 = game.Lighting.Obby:Clone()
players = game.Players:GetChildren()
while true do
	wait(1)
	for i = 5, 1, -1 do
		h.Text = "Choosing map in: "..i
		wait(1)
	end
	h:Remove()
	
	
	if num == 1 then -- if the first map is picked
		h = Instance.new('Hint', workspace)
		m.Text = "Map Number "..num.." Has Been Chosen!"
		wait(3)
		m.Text = "Sword Fight, Created by EternallySpeedy"
		wait(3)
		m.Text = "Be the last one alive!"
		m:Remove()
		wait(3)
		h.Text = "Loading Map..."
		wait(5)
		map.Parent = game.Workspace -- loading the map
		map.Name = "Map"
		map:MakeJoints()
		h.Text = "Teleporting Players..."
		wait(3)
	    h:Remove()
		target = Vector3.new(48.7, 0.5, 32.455) -- teleporting the players
		for i, v in pairs(game.Players:GetChildren()) do
		v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0))
		m = Instance.new('Message', workspace)
		h = Instance.new('Hint', workspace)
		m.Text = "3"
		wait(1)
		m.Text = "2"
		wait(1)
		m.Text = "1"
		wait(1)
		m.Text = "Begin!"
		wait(1)
		m:Remove()
		sword:Clone().Parent = game.Players.LocalPlayer.Backpack
		end
		for i = 60, 1, -1 do
			h.Text = "Round ends in: "..i -- countdown until the round is over
			wait(1)
			end
		h.Text = "The round is over."
		wait(1)
		map:Remove()
		wait(5)
		end
	for i = 15, 1, -1 do -- countdown until the loop restarts
		h.Text = "Intermission: "..i
		wait(1)
		end
		m:Remove()
		h:Remove()
		m = Instance.new('Message', workspace)
		h = Instance.new('Hint', workspace)
		end


	if num == 2 then -- If the second map is picked
		h = Instance.new('Hint', workspace)
		m.Text = "Map Number "..num.." Has Been Chosen!"
		wait(3)
		m.Text = "Obby 1, Created by EternallySpeedy"
		wait(3)
		m.Text = "Be the first to finish!"
		m:Remove()
		wait(3)
		h.Text = "Loading Map..."
		wait(5)
		map2.Parent = game.Workspace -- loading the map
		map2.Name = "Map2"
		map2:MakeJoints()
		h.Text = "Teleporting Players..."
		wait(3)
		target = Vector3.new(48.7, 0.5, 10) -- teleporting players
		for i, v in pairs(game.Players:GetChildren()) do
		v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0))
		m = Instance.new('Message', workspace)
		h = Instance.new('Hint', workspace)
		m.Text = "3"
		wait(1)
		m.Text = "2"
		wait(1)
		m.Text = "1"
		wait(1)
		m.Text = "Begin!"
		wait(1)
		m:Remove()
		for i = 60, 1, -1 do -- countdown until the round is over
			h.Text = "Round ends in: "..i
			wait(1)
			end
		h.Text = "The round is over."
		wait(1)
		map2:Remove()
		wait(5)
		end
	for i = 15, 1, -1 do
		h.Text = "Intermission: "..i -- countdown until the loop restarts
		wait(1)
		end
		m:Remove()
		h:Remove()
		m = Instance.new('Message', workspace)
		h = Instance.new('Hint', workspace)
	end



2 comments

0

I found a problem. Try moving your maps to ServerStorage. Lighting used to be a good place to put items like that, but ServerStorage is more secure and more reliable. If that doesn't work then I'll look at my minigame script and see what another problem might be. :D

0

It's not that, I changed the if num == 2 to elseif num == 2, but there is an error. It now says, "Expected , got elseif"

2 answers

I think that its because you put your if statement that checks if the num == 2 is in a if statement the checks if the num == 1. Try Backspaceing the second If statement out of the first If statement

1 comment

0

I don't think the second if statement is in the first one, I ended the first if statement in the first part.

Looking at the full script, there seem to be two main problems. First and foremost, you didn't add the second map script inside of the while loop. Therefore the script would only pick the first map if everything else worked. But I said there was a second problem: the random number for the map is generated outside of the while loop, so if it generates 2 as it stands now, it will continue looping indefinitely without ever picking a map.

4 comments

0

So first I deleted the while true do to identify which end was with it. I moved that end to the end of the script and added the while true do back, but the script is still not working. I also moved the num = math.random(1,2) inside the loop. Any more ideas?

0

Nevermind, I fixed it!!!! I changed the if to an elseif and put it inside the first if, worked like a charm

0

Trying to run the script as minimalistically as possible outputted that on a specific line you use the localplayer property of the Players service, however, this property only works in a localscript. Use the v variable from your loop instead. Other than that, it appears to run. For future reference, try to post the output when asking for help.

0

Okay

This discussion is preserved as it was. New answers, comments, and votes are closed.