Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
OFF_S4LE 127
3 years ago

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

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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



1
If it didn't work send a comment JesseSong 3916 — 3y
0
all of them still OFF_S4LE 127 — 3y
0
fire at once and print OFF_S4LE 127 — 3y
0
minigame "" was fired OFF_S4LE 127 — 3y
View all comments (12 more)
1
i'll edit it later JesseSong 3916 — 3y
0
kk OFF_S4LE 127 — 3y
1
Why do you have scripts for different Minigames? That's why it is printing for each minigame JesseSong 3916 — 3y
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 MarkedTomato 810 — 3y
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 OFF_S4LE 127 — 3y
0
instead of making them in seprate scripts should i make evrything controlled by that one script? OFF_S4LE 127 — 3y
1
yes, only if you want to get something from the local player JesseSong 3916 — 3y
0
thanks OFF_S4LE 127 — 3y
0
you can teleport player's character with changing the CFrame of the HumanoidRootPart MarkedTomato 810 — 3y
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" JesseSong 3916 — 3y
0
that wouldn't work, because its getting the table of all the descendants. You also, forgot to include the parenthensis in :FireServer() JesseSong 3916 — 3y
0
and also, even if it works it won't be what he's looking for. JesseSong 3916 — 3y
Ad

Answer this question