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

how do I fix my intermission script loading the map multiple times?

I am a beginner scripted and I made an intermission script, and I got it to work, but when I tested it out it loaded my map multiple times and messed my game up. I am pretty sure that it is because I used a local script instead of a script, but I am not sure how to turn my code into something usable by a server script.

local Players = game:GetService("Players")
local tvalue = script.Parent.StatusTag
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local loadMapEvent = ReplicatedStorage:WaitForChild("LoadMapEvent")
 local finishGameEvent = ReplicatedStorage:WaitForChild("FinishGameEvent")
function beginGame()
	wait(1)
	loadMapEvent:FireServer()
	if game.Players.NumPlayers > 1 then
		for i = 10, 0, -1 do
		wait(1)
		tvalue.Text = "Intermission: " .. i .. ""
		if i == 0 then
			tvalue.Text = "Game Started!"
			local function teleAll(x, y, z)
	    		local pos = Vector3.new(x, y, z)
	    		for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
	        		if plr.Character then
	            		plr.Character:MoveTo(pos)
					end
				end
			end
			
			wait(0.2)
			teleAll(0, 3, 0)
			
		end
	end
else
	tvalue.Text = "Need 2 or more players to begin."
end
	
end
beginGame()
finishGameEvent.OnClientEvent:Connect(beginGame)

1 answer

Ok so I finally figured it out, used bindable events. I used BindableEvent:Fire() in the script that originally sent the event that the game was finished to replace the finishGame function, after doing

local BindableEvent = game.Workspace:WaitForChild("BindableEvent")

Also using the line of code above, I put this in the thing that generates the map

BindableEvent.Event:Connect(function()
	loadMap() -- this is the function used to make the map
end)

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