Trying to make script that changes image on button press, however output throws error “attempt to index boolean with ‘changed’” or “attempt to index boolean with ‘GetPropertyChangedSignal’”.
I’ve tried changing the event that fires (Changed or GetPropertyChangedSignal) and adding/removing .Value after the BoolValue, and making the bool a variable within the script.
If it matters at all, I’m using a LocalScript for this. My hierarchy looks like this:
This is the code for the script:
local button = script.Parent
button.Selected:GetPropertyChangedSignal('Value'):Connect(function()
if button:FindFirstChild("Selected").Value then
button.Image = "rbxassetid://15583667722"
elseif not button:FindFirstChild("Selected").Value then
button.Image = "rbxassetid://15615372560"
end
end)
The error you are receiving could possibly be because the script is not reconizing the Selected object. Try creating a variable for it using the WaitForChild method.
Also, I don’t know is this will help or not, but maybe try changing the script from local to server. I’m not sure why, but I’ve had problems in the past using GetPropertyChangedSignal function on the client before.
This doesn’t work, because the script is mistaking “button.Selected” for the actual selected property of the button. Change the line like this:
local button = script.Parent
button:WaitForChild("Selected"):GetPropertyChangedSignal('Value'):Connect(function()
if button:FindFirstChild("Selected").Value then
button.Image = "rbxassetid://15583667722"
elseif not button:FindFirstChild("Selected").Value then
button.Image = "rbxassetid://15615372560"
end
end)