How do I fire a bindable event from a module script?

Module Script:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local bindables = ServerStorage:WaitForChild("Bindables")
local updateCurrencyEvent = bindables:WaitForChild("UpdateCurrency")
			for i, player in ipairs(Players:GetPlayers()) do
				local waveAmount = waves[mode]["waveAmount"]
				local waveMultiplier = waves[mode]["waveMultiplier"]
				local bonusAmount = waves[mode]["bonusAmount"]
				local reward = waveAmount+waveMultiplier+bonusAmount
				
				updateCurrencyEvent:Fire(player, "Stars", reward)
				player.PlayerGui.GameGui.EndScreen.Stats.Currency.Text = "Currency Earned: " .. reward
			end

Server script:

local function updateCurrency(player, currency, amount)
	
	data[player.UserId].currency += amount
end
updateCurrencyEvent:Connect(updateCurrency)

So i’m trying to use a bindable event from my module script to award players some currencies but i keep getting this error, and I have tried many times

updateCurrencyEvent.Event:Connect(updateCurrency)

That’s a RemoteEvent, not a BindableEvent.

ohhh, I put a remoteEvent instead that’s why it didn’t work :sob:

Hello, kind of just scripting here without testing but, this may work out for you. Good luck!

Module Script:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local bindables = ServerStorage:WaitForChild("Bindables")
local updateCurrencyEvent = bindables:WaitForChild("UpdateCurrency")

local waves = {
    ["mode"] = {
        waveAmount = 100,
        waveMultiplier = 2,
        bonusAmount = 50
    }
}

for i, player in ipairs(Players:GetPlayers()) do
    local mode = "mode"
    local waveAmount = waves[mode]["waveAmount"]
    local waveMultiplier = waves[mode]["waveMultiplier"]
    local bonusAmount = waves[mode]["bonusAmount"]
    local reward = waveAmount + waveMultiplier + bonusAmount
    
    updateCurrencyEvent:Fire(player, "Stars", reward)
    player.PlayerGui.GameGui.EndScreen.Stats.Currency.Text = "Currency Earned: " .. reward
end

Server script:

local ServerStorage = game:GetService("ServerStorage")

local bindables = ServerStorage:WaitForChild("Bindables")
local updateCurrencyEvent = bindables:WaitForChild("UpdateCurrency")

local data = {}

local function updateCurrency(player, currency, amount)
    if not data[player.UserId] then
        data[player.UserId] = {currency = 0}
    end
    data[player.UserId].currency += amount
end

updateCurrencyEvent.Event:Connect(updateCurrency)

pls mark that as the solution ty

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