Jump to content

Recommended Posts

Hello, I have a problem I can't fix myself :(. If someone could help me that would be great :)!

This's the code

local equip = inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)

equip.components.finiteuses:Use(10)

What I want to do is damage the equip by 10 points but the game crashes saying "attempt to index field finiteuses a nil value" even though my equip has that component!

This is inside modmain.lua, I would appreciate any kind of help :D!

Edited by SuperDavid

GetEquippedItem can return nil, so check against that before touching it.

There's also the case that whatever is being held doesn't have that component and so there's another thing you'd need to check against.

If you're wanting a specific prefab to be affected then compare against the equip's prefab name to the one you want.

2 hours ago, CarlZalph said:

There's also the case that whatever is being held doesn't have that component and so there's another thing you'd need to check against.

This was the problem, I did this & it worked! Thanks man

if equip.components.finiteuses then
	equip.components.finiteuses:Use(10)
	end

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...