BoolValue not changing

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

If anyone asks, both scripts are in ServerScriptService.

Ok so whenever you call a value it will return that number. .Value can be override. When stored in a variable

E.g

local myvariable = this.Value

myvariable= 5
 

this.Value never got changed it’s just the myvariable got overwritten.

Instead you need to do


local myvariable = this

myvariable.Value = 5


We have now updated the value of that object as we have not overwritten the variable

1 Like

isRunning.Value = <value> and not isRunning = <value>

Aha, thank you! You know, I was thinking that may be the problem, and I was going to try that fix, but I had to go off my PC for a moment and then I forgot about that. Thanks for the help. Will remember next time!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.