Why does this value not go up or down?

Hello! So, I am making a FNAF game on Roblox and I made it so when you close a door a value goes up. It used to work but now it isn’t.

This is a script also

DoorButton.ClickDetector.MouseClick:Connect(function()
	if game.Workspace.DoorButton.Status.Value == "OPENED" then
		game.ReplicatedStorage.PowerUsage.Value = game.ReplicatedStorage.PowerUsage.Value - 1
	elseif game.Workspace.DoorButton.Status.Value == "CLOSED" then
		game.ReplicatedStorage.PowerUsage.Value = game.ReplicatedStorage.PowerUsage.Value + 1
	end
end)

Try adding an else statement to detect failures, it’s better to get errors than not! and with that said do you see anything in your logs?

DoorButton.ClickDetector.MouseClick:Connect(function()
	if game.Workspace.DoorButton.Status.Value == "OPENED" then
		game.ReplicatedStorage.PowerUsage.Value = game.ReplicatedStorage.PowerUsage.Value - 1
	elseif game.Workspace.DoorButton.Status.Value == "CLOSED" then
		game.ReplicatedStorage.PowerUsage.Value = game.ReplicatedStorage.PowerUsage.Value + 1
    else
        error("Unkown door button status! " .. game.Workspace.DoorButton.Status.Value)
	end
end)
1 Like

I have tried to implement your script and it works fine. I found that you named your object as a door. Maybe the problem is on the script that is controlling that object.

4 Likes

I got no errors and no extra parts with the same name

1 Like

What is game.Workspace.DoorButton.Status.Value set to?

Maybe you have made a spelling mistake when setting it?

Is it a local script? could you show your explorer like in @PlAyErS625 's video?

3 Likes

I found no spelling errors on roblox studio

its werid since it worked before and just broke

I found the issue! Though am not sure how to fix it. This is the power system script.

local Power = game.ReplicatedStorage.Power
local PowerUsage = game.ReplicatedStorage.PowerUsage

game.ReplicatedStorage.NightStart.OnServerEvent:Connect(function()
	while Power.Value > 0 do
		Power.Value -= Power.Value >= PowerUsage.Value and PowerUsage.Value or Power.Value
		task.wait(5 - PowerUsage.Value)
	end
end)

local Debounce = false

while wait(0.1) do
	game.Workspace.Power.SurfaceGui.PowerText.Text = "Power ".. Power.Value.. "%"
	if Power.Value == 0 then
		local Debounce = false
		if Debounce == false then
			Debounce = true
			game.Workspace.DoorButton:Destroy()
			game.Workspace.LightButton:Destroy()
			game.Workspace.DoorButton2:Destroy()
			game.Workspace.LightButton2:Destroy()
			game.Workspace.Door:Destroy()
			game.Workspace.Door2:Destroy()
			game.Workspace.Power:Destroy()
			game.Workspace.Sounds["FNaF 1 Door Light [Loop]"]:Stop()
			game.Workspace.Sounds["FNaF 1 Door Light [Loop]2"]:Stop()
			game.Workspace.Sounds["phone"]:Stop()
			game.Workspace.Sounds["[FNAF: PhoneGuy Night 1]"]:Stop()
			game.Workspace.Sounds["power outage sound effect"]:Play()
			wait(1)
			script:Destroy()
		end
	end
end

What is the issue? How does this script related to it? What are you expecting this script to do and what is it actually doing? please answer all of the questions so we can help as best as possible

I notice that without the power script. It would work. Am guessing it was the top script since when I added it. It stopped working

right if you have a while loop the code after it will not run until the while loop has finished, you could move the while loop to the bottom or put it in a task.defer call like so

task.defer(function()
	while wait(0.1) do
		game.Workspace.Power.SurfaceGui.PowerText.Text = "Power ".. Power.Value.. "%"
		-- etc ...
	end
end)