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

If statement returning false but it should be returning true, what should i do?

Okay so, i'm doing a machine that when the player uses it with a tool equipped it removes the tool and give the user a new one in exchange, here is the code:


function Triggered2(Player)
	local backpack = Player.Backpack
	local char = Player.Character
	local tool = char:FindFirstChildOfClass("Tool")
	print(tool)
	if DB2 == false then
		DB2 = true
		if value.Value == 0 then
			if tool ~= nil then
				print("code works till here")
				if tool=="[SCP] Card-L5" then
					print("got if")
					tool:Destroy()
					local card = folder:FindFirstChild("Plastic Card")
					local card2 = card:Clone()
					card2.Parent = backpack
				
				else print("if is false")
				end
			end	
		end
		DB = false
	end
end

Here's the prints

  14:49:53.313  [SCP] Card-L5  -  Server - Main:40
  14:49:53.314  code works till here  -  Server - Main:45
  14:49:53.314  if is false  -  Server - Main:56

I already tried converting to string, changing the card name, i tried a lot of things and nothing worked so i'm here to see if someone got a solution for me

1 answer

✓ Accepted answer

You missed the .Name from Tool, so what it's doing is comparing the tool object to a string, which is, of course, always going to be false:

if tool.Name == "[SCP] Card-L5" then

1 comment

0

that was it! Thank you!

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