Hello.
I was wondering if I can use if not
or ~=
Since I am using a ServerScript
by the way.
When a WalkSpeed
of a Player changes, it prints the player’s WalkSpeed
Sorry if it’s short.
they are the same thing so it is up to you. for example,
local value = false
if not value == true then
print("hi")
end
is the same
local value = false
if value ~= true then
print("hi")
end
dont forget to mark this as a solution if this helps
You wouldn’t even need a not
or ~=
for this. You can just use a Changed.
event or use GetPropertyChangeSignal
to know when the walk speed changes.
Just to simplify it even more:
local value = false
if not value then
print("Its false")
else
print("Its true")
end
--Same thing as
local value = false
if value ~= true then
print("Its false")
else
print("Its true")
end
--Is the same thing of this too
local value = false
if not value == true then
print("False")
else
print("True")
end
That isn’t always true. For example:
print(not Humanoid == OtherHumanoid)
will always print false
but this:
print(Humanoid ~= OtherHumanoid)
will print true
if the Humanoid
is different than the OtherHumanoid
This is always true:
print(not(Humanoid == OtherHumanoid))
You not are using the not
keyword correctly.
Yes, not (Humanoid == OtherHumanoid)
is identical to Humanoid ~= OtherHumanoid
. But using ~=
is preferable because it is shorter than the latter and it still makes sense. Just don’t use
not Humanoid == OtherHumanoid
in place of Humanoid ~= OtherHumanoid
like @jakebball2019 suggested
They can both be acceptable in most regards; it’s more-so user preference. Here are some simple implementations.
I typically would use not
in the case of checking to see if something is either false or nil. For example:
local Value = false
if not Value then
print("This is false!")
else
print("This is true!")
end
Or
--Let's assume this is in a regular script checking for a humanoid, and that the Player variable is already defined.
local Humanoid = Player:FindFirstChildOfClass("Humanoid")
if not Humanoid then return end
print("There is a humanoid!")
~=
is better suited for anything that isn’t a boolean. Numbers, Strings, Enums, etc.
--Let's assume the Player variable is already defined, and we're looking for a specific UserId.
local ID = Player.UserId
if ID~=2024705 then return end
print("We found the appropriate player!")
Now, if we’re talking about watching a player’s walkspeed:
I would take @SpaceDice999’s advice and try to utilize Changed or GetPropertyChangedSignal. Personally, GetPropertyChangedSignal is the better option in this case. You can check the link for that if you want to know more about how to use it. Then in the function that watches the change in walkspeed (if any, for whatever reason you need it to), you can use ~=
. Though with numbers, it may be better to make use of >
,<
,>=
(greater than or equal to) and/or <=
(less than or equal to).