One use item deletes itself when unequipped but doesn't get used

Alright so i have this one use item, and whenever you unequip it while its being used it destroys but then it doesn’t get used

Its a bandage and whenever you use then unequip it destroys and doesn’t heal…

Any help would be nice, thanks!

local Itemused = script.Parent.Itemused

Itemused.Changed:Connect(function()
	if Itemused.Value == 1 then
		wait(4.3)
		script.Parent:Destroy()
	end
end)

local Itemused = script.Parent.Itemused
I’m assuming this is referencing a boolValue in your model/item/whatever, in which case you should be using this instead:
local Itemused = script.Parent.Itemused.Value
this is because Itemused is a reference to the boolValue object, when in reality you want the boolvalue’s Value, which is the actual boolean.

References to objects are considered truthy when they exist, causing your current problem.

the itemused is basically another script that you can toggle to have more than one use, so instead of 1 use you can turn it into 2 use or 3 use (its also a number value)

also how can that connect to my problem?

My apologies, I should stop attempting to help late night.

However, the last sentence at the end of my post is still probably what you’re looking for:

References to objects are considered truthy when they exist, causing your current problem.

if Itemused is a script, then even if Value doesn’t exist, trying to check for it will (likely) still return truthy values.

If you’ve got your script set up where Value is a local inside the Itemused script, that’s not something that’s possible. boolValue or intValue objects would be a simple way around this problem.

However, keep in mind cheaters can very likely alter this value as anything that is client-replicated (such as anything part of an in-hand tool) is something they can touch.

No worries, i am kind of a night owl lol, well do i basically change my number value to a bool or int value?

Edit: …Wow, Lithiio. That is a hilariously unfortunate hashed filename.

local Itemused = script.Parent.boolValue

Itemused.Changed:Connect(function()
	if Itemused.Value == 1 then
		wait(4.3)
		script.Parent:Destroy()
	end
end)

Sorry for being a bit slow, not really good at values. but ill try this out right now. Thank you so much!!

1 Like

Sorry, I’m slow too; just realized you want to make multi-use consumables. Switch the boolValue for an IntValue for the same result.

Okay i used an int value, and now whenever i unequip the item you can start using the item more than one time

Are you editing the IntValue to change the result desired?

Alternatively, are you making sure the change is being replicated properly? if the IntValue is on the server then any scripts on the client cannot alter it.

The int value is inside the tool, if thats what your trying to say

Let me just show you what the value script is

script.Parent.Activated:Connect(function()
	script.Parent.Itemused.Value = script.Parent.Itemused.Value + 1
end)

I’m probably going to back out here with a few parting words:
That sounds like the kind of problem that you’ll need to learn replication to solve.

Use remote event/remote function that send signal to server, check if the tool already used, and delete the tool.

Okay, i’ll try that out. Not really sure on how to use remote events either tbh lol

1 Like

Get started out today with this

Alright, thanks for helping me out guys!

1 Like
local Tool = script.Parent

Tool.Activated:Connect(function()
	--Do tool stuff here.
	Tool:Destroy()
end)

Simple single use tool script.

1 Like

but then how i can i make it so it can be used a certain amount of times then destroy, this is really confusing me sorry!

local Tool = script.Parent

local Uses = 0

Tool.Activated:Connect(function()
	Uses += 1
	
	if Uses >= 10 then
		Tool:Destroy()
	end
end)

You’d need slightly different logic for that, see above.