New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How i can use correctly the Bindable Events?

Asked by 10 days ago
Edited 10 days ago

Sorry for bad english,

I have create a BindableEvent inside the Backpack, called "RefreshPetsEquipped"

I need close the PetsInvFrame when a player buy a gamepass.

In a LocalScript:

local RefreshPetsEquipped = player.Backpack:WaitForChild("RefreshPetsEquipped")

local function OnEquippedFrame()
    PetsInvFrame.Visible = false
    PetsFrame:ClearAllChildren()
    EquippedFrame:ClearAllChildren()    
end
RefreshPetsEquipped.Event:Connect(OnEquippedFrame)

Inside the Script i have add this when the purchase is correct:

local StarterPack = game:GetService("StarterPack")
local RefreshPetsFrame = StarterPack:WaitForChild("RefreshPetsEquipped")
---blablabla
print("Test")
RefreshPetsFrame:Fire()

I see the "Test" when i buy the Gamepass correctly, but the PetsInvFrame still visible. 100% sure i wrong with use the BindableEvent. Who can help me?

0 Errors in Output

1 answer

Log in to vote
1
Answered by 10 days ago
Edited 9 days ago

It would seem like you're trying to communicate with the client using BindableEvents. If you have FilteringEnabled set to true, this is an impossible task.

You are also referencing the BindableEvent inside of the StarterPack, but for the player it's in the backpack so you wouldn't be connecting to the same event in the localscript that you would be firing in the server script.

I'm going to assume that you have FilteringEnabled set to true, in which case if you want to communicate with the client the best way is to use RemoteEvents.

You can try these

LocalScript

local RefreshPetsEquipped = game.ReplicatedStorage:WaitForChild("RefreshPetsEquipped")

local function OnEquippedFrame()
    PetsInvFrame.Visible = false
    PetsFrame:ClearAllChildren()
    EquippedFrame:ClearAllChildren()    
end
RefreshPetsEquipped.OnClientEvent:Connect(OnEquippedFrame) --//.OnClientEvent will wait for a signal from the server

Server

local RefreshPetsFrame = game.ReplicatedStorage:FindFirstChild("RefreshPetsEquipped") or Instance.new("RemoteEvent", game.ReplicatedStorage) --//Making the RemoteEvent if it's not already there and sending it to ReplicatedStorage
RefreshPetsFrame.Name = "RefreshPetsEquipped" --//Have to give it the proper name in order for the client to find it
---blablabla
print("Test")
RefreshPetsFrame:Fire()

Hopefully this helps.

0
I have add (player) inside the function and change the Fire with FireClient(player), now work perfectly, ty GuerraReturns 52 — 10d
0
Ah yes, sorry I forgot to edit that part. Glad I could help. CeramicTile 538 — 9d
Ad

Answer this question