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

I'm trying to make a mini gametype game, it will choose a random remote event to fire?

For some reason it fires all 3 events at once, any fix? Heres the mini game script the fires the remote event :

wait(5)
	

local ServerScriptService = game:GetService("ServerScriptService")

local Minigame1 = ServerScriptService.MinigameScript:WaitForChild("Minigame1")
local Minigame2 = ServerScriptService.MinigameScript:WaitForChild("Minigame2")
local Minigame3 = ServerScriptService.MinigameScript:WaitForChild("Minigame3")
local map = math.random(1, 3)

--Checking if there are atleast 2 players in the game

wait(0.1)
	
	--Choosing MiniGame

	if map == 1 then
		print("Minigame 1 has been chosen")
		Minigame1:FireServer()
	else
		if map == 2 then
			print("Minigame 2 has been chosen")
			Minigame2:FireServer()
		else
			if map == 3 then
				print("Mini game 3 has been chosen")
				Minigame3:FireServer()
			end
		end
	end



There are scripts inside the event, which just print "Minigame 1 fired", ect

Video of studio, scripts and output:

https://imgur.com/a/zMz4Vpc

1 answer

✓ Accepted answer

##Problem: (Re-edited)

The reason it printed out multiple times was that there were all in different scripts. What you could've done, was printed them out in the same scripts.

Solution

Make sure it's all in one script!

Recommendation(s)

  • Use tables, as they save a lot of time!

Fixed Script

local ServerScriptService = game:GetService("ServerScriptService")
local tabs = {
	Minigame1 = ServerScriptService.MinigameScript:WaitForChild("Minigame1"),
	Minigame2 = ServerScriptService.MinigameScript:WaitForChild("Minigame2"),
	Minigame3 = ServerScriptService.MinigameScript:WaitForChild("Minigame3"),
}

wait(5)


local map = math.random(1,#tabs)

--Checking if there are at least 2 players in the game

wait(0.1)

--Choosing MiniGame
if map == tabs[1] then
	print("Minigame 1 has been chosen")
	tabs[1]:FireServer()
else
	if map == tabs[2] then
		print("Minigame 2 has been chosen")
		tabs[2]:FireServer()
	else
		if map == tabs[3] then
			print("Mini game 3 has been chosen")
			tabs[3]:FireServer()
		end
	end
end



16 comments

1

If it didn't work send a comment

0

all of them still

0

fire at once and print

0

minigame "" was fired

1

i'll edit it later

0

kk

1

Why do you have scripts for different Minigames? That's why it is printing for each minigame

0

I think you can make this shorter by doing: if map == tabs[map] then print("Minigame " .. map " has been chosen") tabs[map]:FireServer end

0

mhm i was trying to print a minigame then teleport the players the the playing section kinda like super bomb survival then inside the remote event script it would be the script for the minigame

0

instead of making them in seprate scripts should i make evrything controlled by that one script?

1

yes, only if you want to get something from the local player

0

thanks

0

you can teleport player's character with changing the CFrame of the HumanoidRootPart

0

@MarkedTomato where you said: "I think you can make this shorter by doing: if map == tabs[map] then print("Minigame " .. map " has been chosen") tabs[map]:FireServer end"

0

that wouldn't work, because its getting the table of all the descendants. You also, forgot to include the parenthensis in :FireServer()

0

and also, even if it works it won't be what he's looking for.

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