BoolValue Not Changing

So, I have a BoolValue that I’m attempting to change with a script. For some odd reason, it doesn’t seem to work.

local button = script.Parent
local value = game.ReplicatedStorage.DetailedLighting

local function onButtonActivated()
	if value.Value == true then 
		value.Value = false
	else
		if value.Value == false then
			value.Value = true

			end
		end
	end

Okay, so I have a setting GUI with buttons in it. At the moment, I’m trying to make it so that if the player clicks on a button in the GUI, it’ll change a BoolValue in ReplicatedStorage. If that BoolValue is set to “true”, then the setting activates. If the BoolValue is set to “false”, it deactivates. It doesn’t give me any errors in the output, and it all seems normal, so any idea why it isn’t changing the BoolValue?

It IS a local script.

Oh yeah, and I need the BoolValue to start false

i suggest ya use remote function/event

How would I go about doing that?

it wont change the value for other scripts since you’re doing this in a local script you would have to do a remote event for the value to change.

local script

local remoteevent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
remoteevent:FireServer()

server script

local remoteevent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
remoteevent.OnServerEvent:Connect(function()

end)

That server script would go in ServerScriptService correct?

1 Like

yes, it will go there (30 word :uwaaa:)

probably have to do something like this

local button = script.Parent
local value = game.ReplicatedStorage.DetailedLighting

local function onButtonActivated()
	if value.Value == true then 
		RemoteEvent:FireServer(false)
	else
		if value.Value == false then
			RemoteEvent:FireServer(true)
			end
		end
	end

Also, is a BoolValue the correct course of action here? I’m trying to make the settings client sided, not for the whole server.

then that wouldnt work with the bool value

What should I do instead? limitlimitlimit

Basically, I’m trying to make client sided settings.

probably something like this

local button = script.Parent
local graphics = false

local function onButtonActivated()
	if graphics then 
		graphics = false
        -- Insert Code to Change Graphics --
	elseif graphics == false then
	    graphics = true
        -- Insert Code to Change Graphics --
		end		
	end
end

So would this go into a regular script inside the button?

You need a local script in the button since you’re changing it locally and the local graphics is basically the bool value

First of all.
Client server replication, Local scripts can change objects, but it won’t be replicate to the server.

So if you’re listening for the BoolValue to change on server, it won’t fire.

However, if this BoolValue is only used by the Client, and the value still isn’t changing, you might want to look if the Function is actually being called.

Can you show us the event that calls onButtonActivated ?

Reminder, you can add Breakpoints to your code to step through it and check what it is doing, or use print to see what the bool value is before and after calling your function.

You can references to these things on Roblox’s c Developer Hub

Ok, so now I’m trying to change the image of the button in the script when it is clicked:

local button = script.Parent
local graphics = false

local function onButtonActivated()
	if graphics then 
		graphics = false
		button.Image = "rbxassetid://7793113915"
	elseif graphics == false then
		graphics = true
		button.Image = "rbxassetid://7426307322"
	end		
end

image

Sorry about this, kinda new.

I found out that the method I was using wouldn’t be ClientSided, so I’m trying to learn the other method.

I believe this would work

local button = script.Parent
local graphics = false

local function onButtonActivated()
	if graphics == true then 
		graphics = false
		button.Image = "rbxassetid://7793113915"
	elseif graphics == false then
		graphics = true
		button.Image = "rbxassetid://7426307322"
	end		
end

button.MouseButton1Click:Connect(onButtonActivated)
1 Like

Oh haha, I forgot about that part.