Issues with checking bool values

Trying to check if a bool value by doing if not Value then --code end but it doesn’t do the if statement. Similarly, if I do if Value then --code end it also ignores the if statement. I had to resort to doing if Value == true then --code end but that just feels wrong, and inefficient. If statements with bools just seem to work whenever they want and I need to know why.

Here is a bit of code from my script, if you think you need the entire script, then ask

--earlier in the script in a playeradded event
	local played = Instance.new("BoolValue", Player)
	played.Name = "played"
	played.Value = playedGet

--later inside a function also in the same playeradded event
		if not played.Value then
			playedStore:Set(true)
			played.Value = true
		end
1 Like

Have you tried printing the value before the if statement and seeing what you’re getting?

yep, i get false value
30char acters

When you say “ignoring” the if statement, how are you checking this? It may just be that it doesn’t satisfy the if statement condition. You can check this by putting an else after the if statement.

if not(played.Value) then
    print("Satisfied condition for if statement", not(played.Value))
	playedStore:Set(true)
	played.Value = true
else
    print("Didn't sastisfy condition for if statement ", not(played.Value))
end

I just tried printing it on the else statement and nothing happened but it doesn’t seem to update the played save value or the saved boolvalue, but when i rejoin the game the save value and bool value is true. This is really odd. After the game so far works as intended

So I have no idea what the playedStore:Set(true) does but it might be yielding your script so put the played.Value = true before and see what happens.

if not(played.Value) then
    print("Satisfied condition for if statement", not(played.Value))
    played.Value = true
	playedStore:Set(true)
else
    print("Didn't sastisfy condition for if statement ", not(played.Value))
end
1 Like

It didn’t work. playedStore is a datastore2 key btw. Do you know how to use datastore2?

Did it print “Satisfied condition for if statement true” and not change the played.Value to true? I’m not sure what is wrong then. And no, I haven’t used datastore2 yet.

I would recommend doing this

local played = Instance.new("BoolValue", Player)
played.Name = "played"
played.Value = false

-- after that put this.

local data = PutDataStoreNameHere:GetAsync(Player.UserId) -- out ur datastore name for the played value there.
if data then
    played.Value = data
end

if played.Value == false then
    played.Value = true
end



-- after the end of the whole player added function add this.

game.Players.PlayerRemoving:Connect(function(player)
     DataStoreNameHere:SetAsync(player.UserId, player.played.Value)
end)
1 Like

I’m using datastore 2 for this script

oh wait it did work nvm i thought it didnt because the game itself still looked the same but later looking at the explorer it actually set it to true.