Bool Value problem

Hello, i have this script and all players have a BoolValue inside
So i just want execute this script if BoolValue is FALSE
But its giving to me a error, can someone help?

local cd = script.Parent.ClickDetector
local pants1 = script.Parent.Parent.Parent.Char.Pants

cd.MouseClick:Connect(function(tocado)

local pants = Character:FindFirstChildOfClass("Pants")

if tocado.ReadyForHat.Value = false then
tocado.ReadyForHat.Value = true
Character.Pants.PantsTemplate = pants1.PantsTemplate
wait(30)
Character.Pants.PantsTemplate = Pantsggj.Value
tocado.ReadyforHat.Value = false
end
end

if tocado.ReadyForHat.Value = true then
end
end

Error : image

What is the error that it’s giving you firstly

Edit: I should’ve read it all, which line is it giving the error on

1 Like

image
Its giving the error at line

if tocado.ReadyForHat.Value = false then

You have to use == when you want to compare two values.

By using =, you are assigning a value which throws an error

1 Like

Try this

local cd = script.Parent.ClickDetector
local pants1 = script.Parent.Parent.Parent.Char.Pants

cd.MouseClick:Connect(function(tocado)

    local Character = tocado.Character
    if not Character then return end

	local pants = Character:FindFirstChildOfClass("Pants")

	if tocado.ReadyForHat.Value == false then
		tocado.ReadyForHat.Value = true
		Character.Pants.PantsTemplate = pants1.PantsTemplate
		wait(30)
		Character.Pants.PantsTemplate = Pantsggj.Value
		tocado.ReadyforHat.Value = false
	end
end)

This should work featuring the thing @Jxl_s mentioned, and there were some unneeded ends as well, and you didn’t put a ) at the last end

Edit: I realise that you don’t have a variable for the Character, so it will error anyways. I edited my code so it will create a Chararacter variable and if it’s nil, due to the character not being made by the time the player clicks on the button, it will not continue on with the code

1 Like

I changed the code a little bit, the code in game and the code i published here is different
Just was giving error on this line, Thank you for helping :heart:

1 Like

Anytime! I recommend you set the post that has helped you the most as the solution for anyone who may have the same problem to be able to find it easily! If you have anymore issues don’t be afraid to make another post!

1 Like