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?
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
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
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
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)