Map System Glitch

Hello! I have an issue with my map script. I have an admin panel that allows me to start and end games. However, whenever i click the button to start a game with my alt in the server, 2 games start at once. How may i fix it

--This is in a server script inside the admin panel
local TS = game:GetService("TweenService")
local broadcast = game.StarterGui.ScreenGui.Frame
function broadcasts(minigame)
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {ImageTransparency = 0}):Play()
	wait(0.3)
	broadcast.ImageLabel.background.Text = minigame
	broadcast.ImageLabel.background.main.Text = minigame
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {TextTransparency = 0}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {TextTransparency = 0}):Play()
	wait(0.3)
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Rotation = -2}):Play()
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Position = UDim2.new(-0.07, 0,-0.157, 0)}):Play()
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Size = UDim2.new(0, 570,0, 92)}):Play()
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {Rotation = -2}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {Rotation = -2}):Play()
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {TextSize = 20}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {TextSize = 20}):Play()
	wait(1)
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Rotation = 0}):Play()
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {Rotation = 0}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {Rotation = 0}):Play()
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Size = UDim2.new(0,555,0,74)}):Play()
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {TextSize = 14}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {TextSize = 14}):Play()
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {Position = UDim2.new(-0.039, 0,-0.157, 0)}):Play()
	wait(0.5)
	TS:Create(broadcast.ImageLabel, TweenInfo.new(0.2), {ImageTransparency = 1}):Play()
	TS:Create(broadcast.ImageLabel.background, TweenInfo.new(0.2), {TextTransparency = 1}):Play()
	TS:Create(broadcast.ImageLabel.background.main, TweenInfo.new(0.2), {TextTransparency = 1}):Play()
end


script.Parent.MouseButton1Click:Connect(function()
local num = math.random(1,6)
	if num == 1 then
		local cloneSword = game.ReplicatedStorage.maps.Swordfight:Clone()
		cloneSword.Parent = game.Workspace.minigame
		broadcasts("Sword Fight")
	elseif num == 2 then
		local cloneObby = game.ReplicatedStorage.maps.obby:Clone()
		cloneObby.Parent = game.Workspace.minigame
		broadcasts("Obby")
	elseif num == 3 then
		local cloneMaze = game.ReplicatedStorage.maps.Maze:Clone()
		cloneMaze.Parent = game.Workspace.minigame
		broadcasts("Maze")
	elseif num == 4 then
		local clonepotato = game.ReplicatedStorage.maps.Tag:Clone()
		clonepotato.Parent = game.Workspace.minigame
		broadcasts("Tag, Your It")
	elseif num == 5 then
		local cloneFind = game.ReplicatedStorage.maps.Find:Clone()
		cloneFind.Parent = game.Workspace.minigame
		wait(0.2)
		local FindIt = game.ReplicatedStorage.RepItems["You Found It!"]:Clone()
		FindIt.Parent = game.Workspace
		broadcasts("Find it")
		local Extra = game.ReplicatedStorage.RepItems.ExtraPoint:Clone()
		Extra.Parent = game.Workspace
	elseif num == 6 then
		local clone = game.ReplicatedStorage.maps.Dodgeball:Clone()
		clone.Parent = game.Workspace.minigame
		local dodgeballs = game.ReplicatedStorage.RepItems.Dodgeball:Clone()
		dodgeballs.Parent = game.Workspace
		broadcasts("Dodgeball")
	end

end)

This is likely because you don’t have a limitation to how many times the admin can start another game. If the given code is in a LocalScript, you should add a BoolValue in ReplicatedStorage, and use the BoolValue to determine if a minigame is currently active or not.

Example:

local BoolValue = game.ReplicatedStorage:WaitForChild("GameActive")
local StartBtn = script.Parent
local EndBtn -- wherever your 'End Game' button is located

StartBtn.Activated:Connect(function()
	if BoolValue.Value then -- if 'GameActive' value is true
		return
	else -- if it's not true
		BoolValue.Value == true

		-- execute rest of the code
	end
end)

EndBtn.Activated:Connect(function()
	if BoolValue.Value then -- if 'GameActive' Value is currently true
		BoolValue.Value = false -- set value to 'false'

		-- execute code for ending the game
	end
end)

Note: Remember to set the BoolValue to the desired value within your main game system.

1 Like

Alright,Thank you so much! I will try this out

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.