Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to fix attempting to compare boolean?

I am not familiar with booleans and I am not sure how to fix this. The problem is in line 4, if anyone could fix it for me I would appreciate it.

local counter = 0

function playtext(hit)
	if not counter >= 1 then
		counter = counter + 1
		local clone = game.ServerStorage.dialog3:Clone()
		clone.Parent = game.StarterPlayer.StarterPlayerScripts
		wait()
		clone.Disabled = false
	end
end
script.Parent.Touched:Connect(playtext)

1 comment

0

so, with or without the if statement, it would only run once

1 answer

Operator precedence

The logical operator not has higher precedence over all relational operators* (find the list here) so the not is applied to counter and since in Lua non-nil non-false values are truthy, it is the equivalent of if false >= 1 then.

Instead just use the complete opposite of the >= operator which is the < operator

if counter < 1 then
    ...
end
* relational operators are <=, >=, <, >, ==, ~=

This discussion is preserved as it was. New answers, comments, and votes are closed.