Bindable Event Not Working Problem

So, i Encountered an Issue with my Several Bindable Events for a comboing System for NPCs.
i was actually working on Comboing System For Anchored 3D Health bar for NPCs, and i scripted a combo script, and i tested out the combo with AllyNpc For Example. but for some reason, my several Bindable Events doesn’t work and i have no clue how to fix the my Several BindableEvents.

Here’s a Combo Script:

local Syncer = require(script.ComboSyncer)
local Target = script.Parent.Parent.Configuration.Target.Value

while wait() do
	script.Parent.SurfaceGui.TextLabel.Text = "Combo: "..script.Parent.combo.Value
	Syncer.SyncComboRank(script.Parent.combo.Value)
	if script.Parent.combo.Value >= 2 then
		script.Parent.SurfaceGui.TextLabel.Visible = true
	else
		script.Parent.SurfaceGui.TextLabel.Visible = false
	end
end

Target.Combo.Event:Connect(function()
	script.Parent.combo.Value += 1
end)

Target.ComboBreak.Event:Connect(function()
	script.Parent.combo.Value = 0
end)

i have several Bindable Events:
1st Bindable Event Named “Combo”, Combo is a Bindable Event that increases combo value whatever they hit it
2nd Bindable Event Named “ComboBreak”, ComboBreak is a Bindable Event that combo value Resets Back to 0 whatever they miss

i was currently using on script.Parent.Combo:Fire() and script.Parent.ComboBreak:Fire() but it doesn’t work for some reason.

pls give me any solutions to fix the issues?

While loops yield, meaning the two events underneath never get connected.
Move it around to this:

local Syncer = require(script.ComboSyncer)
local Target = script.Parent.Parent.Configuration.Target.Value

Target.Combo.Event:Connect(function()
	script.Parent.combo.Value += 1
end)

Target.ComboBreak.Event:Connect(function()
	script.Parent.combo.Value = 0
end)

while wait() do
	script.Parent.SurfaceGui.TextLabel.Text = "Combo: "..script.Parent.combo.Value
	Syncer.SyncComboRank(script.Parent.combo.Value)
	if script.Parent.combo.Value >= 2 then
		script.Parent.SurfaceGui.TextLabel.Visible = true
	else
		script.Parent.SurfaceGui.TextLabel.Visible = false
	end
end

Also, you could use a .Changed event to detect when the value number changed, and update the UI based off that instead of a while loop which checks ~60 times a second. Heres an example:

Target.Changed:Connect(function(number)
	print(number)
	script.Parent.SurfaceGui.TextLabel.Text = "Combo: "..script.Parent.combo.Value
	Syncer.SyncComboRank(script.Parent.combo.Value)
	if script.Parent.combo.Value >= 2 then
		script.Parent.SurfaceGui.TextLabel.Visible = true
	else
		script.Parent.SurfaceGui.TextLabel.Visible = false
	end
end)

Documentation for how to use .Changed events:

1 Like

Oh my! It Works! Thank you so much!

1 Like

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