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

Using bindable functions for consuming an item in your inventory?

Greetings all,

I have been trying to work this out for hours, I still, clearly have no idea. Basically, I have created a use button for the players inventory, when they use an apple, lets say, it will damage the player(Just for testing purposes). I am using bindable functions with :Invoke() and :OnInvoke(). There is no output errors, and the 'use' button inside the players inventory does nothing!

The code:

-- InventoryModule inside replicated storage

inventoryModule.ConsumeItem = function(player, item)
	local gameItem = game.ReplicatedStorage.Global_Items.Game_Items:FindFirstChild(item.Name)
	if gameItem then
		if player then --It passes the if statements
			item.Use:Invoke(player) --It doesn't  invoke?
		end
	end
end

-- Inside a local script, inside a bindable function, inside the item, inside the players inventory folder. Like this:
	--Player1
		--Inventory
			-- Apple
				--ImageId
				--Item Type
				--Use
					--UseScript

function script.Parent.OnInvoke(player)
	if player and player.Character then
		player.Character.Humanoid:TakeDamage(10)
	end
end

Thanks in advance, Brandon. <3

2 comments

1

Scripts / LocalScripts can't communicate between each other using BindableFunctions -- you would need to use a RemoteFunction for that (not completely solid on how you're set up, so this might not be relevant). Also try printing at different places to see what is running

0

Ah, this explains a lot. Thanks dude, I will give it a shot!

1 answer

um try to replace line 4 with this

 local gameItem = game.ReplicatedStorage.Global_Items.Game_Items:FindFirstChild(item.Name, true)

2 comments

0

I don't think so, I will try it. I think it is to do with Module script not invoking the bindable function! As I say, all the If statements pass through without a problem!

0

strange..

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