Why doesn't my "if not" statement do the opposite of a "if" statement?
Asked by
6 years ago Edited 6 years ago
I'm making a GUI where the player can select a book to use. When the player has done this, I want to see if the player has selected the same book as the player used before or if the player has selected another book so that I don't change the datastore without needing to. I do this by writing an if statement that checks if the book that the player currently has equipped is the same book that the player equipped in the GUI and stop the datastore from being changed if that is the case. However, the following code does not do that. If I change it from "if not" to "if" and then try to equip the same book as I already have equipped, The code run. but if I put back the "if not" and try to equip a book that I don't have equipped, the code doesn't run.
The code is in a server script in ServerScriptStorage
"equipped" stands for the book the player wants to equip
"writingtool" is the dictionary where I store information about the players' stats
"what" is what the player wants to equip between a pen and a book
Code:
01 | game.ReplicatedStorage.EquipPen.OnServerEvent:Connect( function (Player, equipped, what) |
03 | writingtool = WritingTool:GetAsync(Player.UserId) |
04 | if not writingtool [ "Equipped" ] = = equipped then |
05 | writingtool [ "Equipped" ] = equipped |
06 | WritingTool:SetAsync(Player.UserId, writingtool) |
09 | writingtool = WritingTool:GetAsync(Player.UserId) |
11 | print (writingtool [ "Equipped2" ] ) |
12 | if not writingtool [ "Equipped2" ] = = equipped then |
14 | writingtool = WritingTool:GetAsync(Player.UserId) |
15 | writingtool [ "Equipped2" ] = equipped |
16 | WritingTool:SetAsync(Player.UserId, writingtool) |