Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using bindable functions for consuming an item in your inventory?

Asked by 9 years ago

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

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 BlueTaslem 18071 — 9y
0
Ah, this explains a lot. Thanks dude, I will give it a shot! RobloxUserBrandon 20 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

um try to replace line 4 with this

 local gameItem = game.ReplicatedStorage.Global_Items.Game_Items:FindFirstChild(item.Name, true)
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! RobloxUserBrandon 20 — 9y
0
strange.. Layfonex 0 — 9y
Ad

Answer this question