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
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)