Trouble with Boolean values

Hello!

I have been scripting some stuff for my game, and while doing so, I came across an issue.

In my game, I have a script that relies on a boolean value stored inside of ReplicatedStorage to work.

In one part of the script, it calls for the boolean’s value to be turned true, however, it doesn’t quite work.

Here is the part of the script where the issue happens:

game.Players.PlayerAdded:Connect(function(p)
	p.Chatted:Connect(function(chat)
		if chat == "Open sesame!" then
			
			local debounce = game.ReplicatedStorage.debouncevalue.Value
			
			if debounce == false then
				
				local wall = script.Parent
				local sound = script.bell
				local block = game.Workspace.block

				sound:Play()
				wall.Transparency = 1
				wall.CanCollide = false
				block.Transparency = 0
				block.CanCollide = true
				
				wait(0.5)
				
				debounce = true
			else
				
			end
		end
	end)
end)

When I run this script, it’s supposed to turn the debounce value to true after the chat message is said and stay that way forever.

However, the boolean value never turns true and the debounce system completely breaks.

I’ve tried searching for solutions on the DevForum and other places, but nothing works.

Can someone help? Thanks!

1 Like

the reason why it doesn’t work is because you set debounce to the value of the boolean, meaning that the debounce variable is read-only and non editable
this should fix it:

game.Players.PlayerAdded:Connect(function(p)
	p.Chatted:Connect(function(chat)
		if chat == "Open sesame!" then
			
			local debounce = game.ReplicatedStorage.debouncevalue
			
			if debounce.Value == false then
				
				local wall = script.Parent
				local sound = script.bell
				local block = game.Workspace.block

				sound:Play()
				wall.Transparency = 1
				wall.CanCollide = false
				block.Transparency = 0
				block.CanCollide = true
				
				wait(0.5)
				
				debounce.Value = true
			else
				
			end
		end
	end)
end)
1 Like

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