Error immediately firing! Without checking the else of my if statement

Hello, so i’m trying to make a Try Clothing gui, and I was testing everything with printing. But I keep on getting an error while checking if the Shirt is part of the character. This is a local script in the billboard gui.

--//Services
ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local buyPantsButton = script.Parent.BuyPantsButton
local buyShirtButton = script.Parent.BuyShirtButton
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.ChildAdded:Wait()
--//Script
--//Checking for pants and Shirt
if not script.Parent.Adornee.Pants then
script.Parent.BuyPantsButton.Visible = false
elseif not script.Parent.Adornee.Shirt then
script.Parent.BuyShirtButton.Visible = false
end
buyShirtButton.MouseButton1Click:Connect(function()
local shirt = character.Shirt
if shirt then
print("shirt")
else warn("no shirt")
end
end)

When I run this script I immediately get this error in my output without the script even checking the else.
image

You cannot index nil with a roblox object, this is why you use FindFirstChild or WaitForChild.

local shirt = character:FindFirstChild("Shirt")
if shirt then
   print("shirt")
else
   warn("no shirt")
end
1 Like

Omg, thx. Can’t believe I couldn’t remember this, must be the lack of sleep.

1 Like