I want to check if a function is stillrunning on a modulescript by updating a boolValue.
Whilst printing the value’s value on the module script, it is “True”, however when checking it on the server, and printing the value from a server script, it is set to false.
local isRunning = script.Parent.Parent.Script.IsRunning.Value
isRunning = false
function gameModes.RockPaperScissors()
local getPlrs = plrs:GetPlayers()
-- Setup
local folder = rs:FindFirstChild("RockPaperScissors")
local playerChoice = folder:FindFirstChild("PlayerChoice")
local startRoundEv = folder:FindFirstChild("StartRound")
local endGame = folder:FindFirstChild("EndGame")
local updateGui = folder:FindFirstChild("UpdateGUI")
local choices = {"Rock", "Paper", "Scissors"}
local player1Choice = nil
local player2Choice = nil
local player1Score = 0
local player2Score = 0
local selected1
local selected2
local round = 0
local function startRound()
round = round + 1
if round < 5 then
isRunning = true
print(isRunning)
player1Choice = nil
player2Choice = nil
startRoundEv:FireClient(selected1)
startRoundEv:FireClient(selected2)
else
if player1Score > player2Score then
print(selected1.Name .. " wins!")
endGame:FireAllClients(selected1)
isRunning = false
else
print(selected1.Name .. " wins!")
endGame:FireAllClients(selected2)
isRunning = false
end
end
end
local function determineRoundWinner(choice1,choice2)
if choice1 == choice2 then
print("Was a draw")
startRound()
return nil
elseif (choice1 == "Rock" and choice2 == "Scissors") or
(choice1 == "Paper" and choice2 == "Rock") or
(choice1 == "Scissors" and choice2 == "Paper") then
print("Player1:"..player1Score..". Player2:"..player2Score)
player1Score += 1
updateGui:FireAllClients("Player1",player1Score)
startRound()
else
print("Player1:"..player1Score..". Player2:"..player2Score)
player2Score += 1
updateGui:FireAllClients("Player2",player2Score)
startRound()
end
end
local function selectPlayers()
selected1 = getPlrs[math.random(1,#getPlrs)]
repeat
selected2 = getPlrs[math.random(1,#getPlrs)]
until selected1 ~= selected2
print(selected1,selected2)
startRound()
end
playerChoice.OnServerEvent:Connect(function(plr, choice)
if plr == selected1 then
print(plr.Name.."'s choice is "..choice)
player1Choice = choice
else
print(plr.Name.."'s choice is "..choice)
player2Choice = choice
end
if player1Choice ~= nil and player2Choice ~= nil then
determineRoundWinner(player1Choice,player2Choice)
end
end)
selectPlayers()
end
ServerScript:
local module = require(game.ServerScriptService.Gamemodes.ModuleScript)
local plrs = game.Players
local getPlrs = plrs:GetPlayers()
repeat
wait()
print("waiting for players")
getPlrs = plrs:GetPlayers()
until #getPlrs >= 2
print("max players")
local function runModuleWithWait(moduleFunc)
moduleFunc()
wait(2)
while true do
print(script.IsRunning.Value)
if script.IsRunning.Value == false then
print("Mode ended")
break
end
wait()
print("Waiting for mode to end")
end
wait(15)
end
local moduleFunctions = {
module.RockPaperScissors,
module.TugOfWar,
module.Favourites,
module.PublicOrPrivate,
module.MusicalChairs,
module.Exile,
module.PassTheBomb,
module.Spikes,
module.SurviveTheKiller,
module.Weights,
module.CoinFlip,
module.MurdererVsSheriff
}
for _, func in pairs(moduleFunctions) do
runModuleWithWait(func)
end