Bindable event not being received by local script when another local script fires it

  1. What do you want to achieve? Keep it simple and clear!
    I want my local script to run when it receives a bindable event.

  2. What is the issue? Include screenshots / videos if possible!
    The client fires a bindable event, and the script listening for it does not run.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I have tried changing the script that sends the event, the one receiving it, and I have also checked EVERYWHERE for typos.

The card game is very similar to rummy, and this is checking for a run. (same suit, in numerical order.) You press a button to scan your selected cards to see if they are a valid run, and if it is, the script in the button attempts to remove those cards from your deck and puts them down. Here is the problem: It sends the list to the PutDownCards event. But, the script controlling the deck never runs, showing that it never got the event.

Here’s the code for the run check button: (it works, and doesn’t print “firing putdowncards” because the previous line pauses it)

script.Parent.MouseButton1Click:Connect(function()
--checking if the run is valid, all works

	if suitablerun then
        script.Parent.Parent.PutDownCards:Fire(true, cards)
		print("firing putdowncards")
	end
	
end)

And this is the reciever of that script. Most of it is irrelevant, it just doesn’t run. (i know because it never prints “taking cards from player”.)

game:GetService("ReplicatedStorage").Events.DeckStatus.TakeCardsFromPlayer.OnClientEvent:Connect(function(cards)
	print("taking cards from player")
	for i, v in pairs(cards) do
		local removedCard = false
		for i, v in pairs(script.Parent:GetChildren()) do
			if v:IsA("Frame") then
				if v.Name == string.gsub(tostring(v), ",", " ") then
					v:Destroy()
					removedCard = true
					break
				end
			end
		end
		print(removedCard)
	end
end)

Any help would be appreciated. Thanks!

1 Like

If I had to assume, the problem is that your LocalScript is in the wrong place.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local deckStatus = events:WaitForChild("DeckStatus")
local takeCards = deckStatus:WaitForChild("TakeCardsFromPlayer")

takeCards.OnClientEvent:Connect(function(cards)
	print("taking cards from player")
	for _, v in pairs(cards) do
		local removedCard = false
		for _, child in pairs(script.Parent:GetChildren()) do
			if child:IsA("Frame") then
				if child.Name == string.gsub(tostring(v), ",", " ") then
					child:Destroy()
					removedCard = true
					break
				end
			end
		end
		print(removedCard)
	end
end)
1 Like

Right now, it’s in a gui in StarterGui. Its exact location is StarterGui.CardGui(ScreenGui).Container(Frame).LocalScript. Would it not be recieved in a Gui?

I just tried this, and it didn’t work. It is made much better than mine overall, so I am going to use it. Thanks!!!

I fixed it myself using a module script to communicate between the two local scripts.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.