BoolValue doesn't change in Workspace, but in Output it gets changed

I’m trying to do a timer for locking your base and i made a function for the timer, it works just fine the first time, but the second time i try and touch the button, nothing happens, I added prints to try and debug why, but I can’t figure out why it doesn’t work. I check workspace while in Server mode and nothing changed to the bool value, but in Output it appears that the Server changed the value to false.

Here is the code:

local button = script.Parent.Button

local gates = script.Parent.Parent.Gate:GetChildren()
local Stats = script.Parent.Parent.Stats

local LockedTimer = 5

local touched = false

local function timer(timer, button, chosenBase)
	print(chosenBase)

	for i = timer, 0, -1 do
		print(Stats:FindFirstChild("Locked").Value)
		
		button:FindFirstChild("BillboardGui"):FindFirstChild("Frame"):FindFirstChild("TextLabel").Text = i
		Stats:FindFirstChild("Locked").Value = true

		for i, v in pairs(chosenBase:FindFirstChild("Gate"):GetChildren()) do
			if v.Name ~= "Barrier" then
				v.Transparency = 0
				v.CanCollide = true
			end
		end

		task.wait(1)

		if i == 0 then
			Stats:FindFirstChild("Locked").Value = false -- this doesn't change anything in workspace
			print(Stats:FindFirstChild("Locked").Value)
			
			button:FindFirstChild("BillboardGui"):FindFirstChild("Frame"):FindFirstChild("TextLabel").Text = "LOCK YOUR BASE!"
			
			for i, v in pairs(chosenBase:FindFirstChild("Gate"):GetChildren()) do
				if v.Name ~= "Barrier" then
					v.Transparency = 1
					v.CanCollide = false
				end
			end
			
			print(Stats:FindFirstChild("Locked").Value)
		end
	end
end

button.Touched:Connect(function(hit)
	if touched == false	then
		touched = true
		
		if hit.Parent:FindFirstChild("Humanoid") then
			local char = game.Players:GetPlayerFromCharacter(hit.Parent)
			local playerFolder = char:FindFirstChild("playerFolder")
			local hasBase = playerFolder:FindFirstChild("hasBase")

			print(hasBase.Value)

			if Stats:FindFirstChild("Locked").Value == false then
				timer(LockedTimer, button, workspace:FindFirstChild("Bases"):FindFirstChild(hasBase.Value))

				Stats:FindFirstChild("Locked").Value = true
			else
				return
			end
		end
		
		wait(.5)
		
		touched = false
	end

end)

I think the problem might be that youre setting the locked value to true after the timer is finished rather than before

thanks xddddddd. God bless you

1 Like

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