{ANSWERED} The "=" alwas gives a error

so im making a script where if a button is clicked image is changing
this is the script:

local aa = script.Parent
local Image = script.Parent.Image
local Audio = script.Parent.Song


script.Parent.MouseButton1Click:connect(function()
	if
		Audio.Playing = true 
		Image = "image id one"
	else
	    Audio.Playing = false 
	    Image = "image id two"
	end
end)

this is the error :image

i need help

The if statement requires a == (double equals sign) to work.

1 Like

that way the “Image” gives an error
image

1 Like

You need to add then keyword after Audio.Playing == true.

1 Like

Not entirely true. What it requires is a condition. Something that you could say is “false” and something you could say is “true”

if "hello" then
    print"world"
end

will print “world” because strings have “truthiness”

he forgot the then statement.

1 Like

i added “then” but it still didnt work :confused:
image

1 Like

just did and its still not working

1 Like

change it to

if Audio.Playing == true then
   Image.ImageID = 112902314
else 
 --whatever you do here
end

you were tryin to put an id in an object instead of into the imageid property

1 Like

yea, still not working :confused:

1 Like

can i see the entire script? its hard to see why it doesn’t work now

1 Like
local aa = script.Parent
local Image = script.Parent.Image
local Audio = script.Parent.Song


script.Parent.MouseButton1Click:connect(function()
	if
		Audio.Playing == true  then
		Image.ImageID = 112902314
	else
	    Audio.Playing = false 
		Image.ImageID = 73737626
	end
end)
1 Like

firstly, i have no clue why you would be setting the audio playing to false when you already verified that it isnt playing
further, could you try adding prints inside both variations? and do you have any errors in output?

1 Like

So you are checking if the audio is playing?

1 Like

yeah, that way i can change the button image depending if the song is playing or not

1 Like

im setting audio to false because i need it to change the image when song is not playing

oh and ok i will do print stuff

1 Like

Try

local aa = script.Parent
local Image = script.Parent.Image
local Audio = script.Parent.Song

script.Parent.MouseButton1Click:connect(function()
	if Audio.Playing == true  then -- Check if audio is playing 
		Image.ImageID = 112902314
	else -- If audio is not playing then change image to something else
		Image.ImageID = 73737626
	end
end)

Edit: Some changes

1 Like

Here’s my attempt to fix this thread.

local button = script.Parent
local Audio = script.Parent.Song

button.MouseButton1Click:connect(function()
	if not Audio.Playing then -- or: if Audio.Playing == false then
		Audio.Playing = true
		button.Image = "rbxassetid://112902314"
	else
		Audio.Playing = false
		button.Image = "rbxassetid://73737626"
	end
end)
4 Likes

you already verified that the audio isnt playing inside the else .-. please learn how bools work

1 Like

sorry but right when you posted that someone replied a solution :()
but still thanks for helping

1 Like

yeah will do that, im new to scripting

1 Like