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

How i can use correctly the Bindable Events?

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

✓ Accepted answer

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.

2 comments

0

I have add (player) inside the function and change the Fire with FireClient(player), now work perfectly, ty

0

Ah yes, sorry I forgot to edit that part. Glad I could help.

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