-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local ServerStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
------------------
-- GUI Elements --
local textLabel = StarterGui.ScreenGui:WaitForChild("TextLabel")
------------------
-- Remote Events --
local killPlayer = ReplicatedStorage:WaitForChild("killPlayer")
local intermission = ReplicatedStorage:WaitForChild("Intermission")
local teleportPlayers = ReplicatedStorage:WaitForChild("TeleportPlayers")
------------
-- Values --
local InGame = game.Workspace:WaitForChild("InGame")
local InLobby = game.Workspace:WaitForChild("InLobby")
local StringValue = game.Workspace:WaitForChild("Time")
------------
-- Lobby SpawnLocation --
local LobbySpawn = game.Workspace:WaitForChild("SpawnLocation")
-- Maps --
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Maps = {MapsFolder:WaitForChild("Map1"), MapsFolder:WaitForChild("Map2", MapsFolder:WaitForChild("Map3"))}
local selectedMap = Maps[math.random(1, #Maps)]
local map = selectedMap:Clone()
-----------
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character) -- The parameter of the function will refer to the player's Character in this case because the activation of the CharacterAdded event sends the Character instance to the function
while true do
if InLobby.Value == true then
Character.HumanoidRootPart.Position = Vector3.new(LobbySpawn.CFrame)
for i = 5, 0, -1 do
StringValue.Value = "Intermission: " .. i
task.wait(1)
end
-- set these values after the for loop, do not need to check i == 0
InLobby.Value = false
InGame.Value = true
elseif InGame.Value == true then
local char = Character
for _,player in pairs(game:GetService("Players"):GetPlayers())do
if player and player.Character then
local selectedLocation = selectedMap.SpawnLocations:GetChildren()[math.random(1, #selectedMap.SpawnLocations:GetChildren())]
map.Parent = workspace
player.Character:MoveTo(selectedLocation.Position)
end
end
for i = 5, 0, -1 do
StringValue.Value = "Time remaining: " .. i
task.wait(1)
end
map.Parent = game.ServerStorage
InGame.Value = false
InLobby.Value = true
else
error("Not in lobby or game!") -- errors help debugging
end
end
end)
end)
Just stuck as I cannot get figure out how to make math.random reset as when the selectedMap is chosen it just stays the same
Any help is much appreciated thanks