Elseif not working

Why does it keep erroring this when i added an elseif statement?

PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle.Minutes.Value.." minutes"
			elseif Obj.Name == "WoodSword" then
				PickupInfoGui.FtoPickup.Text = "Premium Required to claim this item"
			end

That error tells me that Minutes doesn’t exist? Look around it and see why it doesn’t exist in the first place.

yes, it doesn’t exist but thats why i added an elseif statement

Print what Obj.Handle.Minutes is supposed to be first :thinking:

It’s just a NumberValue

If it doesn’t exist and you want to check if it does, you need to use FindFirstChild.
if Obj.Handle:FindFirstChild("Minutes") then

Now it’s saying attempt to nil with value, how do i make it stop if the item is named “WoodSword”

I don’t have nearly enough code or context to even reasonably give the answer I already gave.

You should probably include a couple more sanity checks before confirming it to be valid:

print(Obj)
print(Obj.Handle)
print(Obj.Handle.Minutes) --Errors at this point maybe
print(Obj.Handle.Minutes.Value)
PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle.Minutes.Value.." minutes"
			elseif Obj.Name == "WoodSword" then
				PickupInfoGui.FtoPickup.Text = "Premium Required to claim this item"
			end
local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Player = game:GetService("Players").LocalPlayer

local Distance = 10
local Folder = workspace.Items

game:GetService("RunService").RenderStepped:Connect(function()
	for i,Obj in pairs(Folder:GetDescendants()) do
		if Obj:IsA("Tool") then
			if Player:DistanceFromCharacter(Obj.Handle.Position) < Distance then
				PickupInfoGui.Adornee = Obj.Handle
				PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle:FindFirstChild("Minutes").Value.." minutes"
			elseif Obj.Name == "WoodSword" then
				PickupInfoGui.FtoPickup.Text = "Premium Required to claim this item"
			end
		end
	end
end)

It prints woodsword and handle

Inside your loop, I’d recommend checking a couple more things before confirming the values:


game:GetService("RunService").RenderStepped:Connect(function()
	for i,Obj in pairs(Folder:GetDescendants()) do
		if Obj:IsA("Tool") and Obj.Handle and Obj.Handle:FindFirstChild("Minutes") then
			if Player:DistanceFromCharacter(Obj.Handle.Position) < Distance then
				PickupInfoGui.Adornee = Obj.Handle
				PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle:FindFirstChild("Minutes").Value.." minutes"
			elseif Obj.Name == "WoodSword" then
				PickupInfoGui.FtoPickup.Text = "Premium Required to claim this item"
			end
		end
	end
end)

It doesn’t adornee to the sword or do anything

It doesn’t work because minutes doesn’t exist and so everything will stop.
You have to check if it is nil before not after.

How do i do that?

You could figure it out I’m sure, I can’t really help more than that cus I have to catch some sleep right now

I tried this

game:GetService("RunService").RenderStepped:Connect(function()
	for i,Obj in pairs(Folder:GetDescendants()) do
		if Obj:IsA("Tool") then
			if Player:DistanceFromCharacter(Obj.Handle.Position) < Distance then
				PickupInfoGui.Adornee = Obj.Handle
				PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle.Minutes.Value.." minutes"
			end
			
			if not Obj.Handle:FindFirstChild("Minutes") then
				if Obj.Name == "WoodSword" then
					PickupInfoGui.FtoPickup.Text = "Premium Required to claim this item"
		end
			end
		end
	end
end)

But im not sure why this isn’t working

What was this suppose to do?

Here’s a nil check

if Obj.Handle:FindFirstChild("Minutes") == nil then
--If minutes does not exist, do stuff
else
--If minutes exists, do stuff
end

Shouldn’t it be else instead of elseif?