Hello, I’m trying to make a spin wheel system, but for some reasons, it gives me an error when trying to get rewarded the reward. this is the error:
attempt to perform arithmetic (add) on table and number
this error occurs at this line specifically:
if Currency then
Currency.Value = tostring(en.convert(Currency.Value) + SpinModule.Spin.Rewards[SpinReward].Amount)
else
this is my whole script:
local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService"):GetDataStore("CVNXAN")
local SpinEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Spin")
local SpinModule = require(game:GetService("ReplicatedStorage"):WaitForChild("SpinModule"))
local en = require(game.ReplicatedStorage.Modules.EternityNum)
local function PlayerJoined(Player)
local PlayerStats = Instance.new("Folder")
PlayerStats.Name = "OtherStuff"
PlayerStats.Parent = Player
local SpinTime = Instance.new("NumberValue")
SpinTime.Name = "SpinTime"
SpinTime.Value = SpinModule.Spin.SpinTimeForReward
SpinTime.Parent = PlayerStats
local Spin = Instance.new("NumberValue")
Spin.Name = "Spin"
Spin.Value = DataStore:GetAsync("Spin"..Player.UserId) or 1
Spin.Parent = PlayerStats
spawn(function()
while wait(1) do
if SpinTime.Value > 0 then
SpinTime.Value -= 1
elseif SpinTime.Value <= 0 then
SpinTime.Value = SpinModule.Spin.SpinTimeForReward
Spin.Value += 1
end
end
end)
end
local function PlayerRemoved(Player)
local PlayerStats = Player:WaitForChild("OtherStuff")
local Spin = PlayerStats:WaitForChild("Spin")
DataStore:SetAsync("Spin"..Player.UserId, Spin.Value)
end
local function StudioSave()
wait(0.7)
end
local function SpinEventFire(Player, SpinReward)
local Spin = Player:WaitForChild("OtherStuff"):WaitForChild("Spin")
if Spin.Value >= 1 then
Spin.Value -= 1
local Currency = Player:WaitForChild("Data"):WaitForChild("Stats"):FindFirstChild(SpinModule.Spin.Rewards[SpinReward].Reward)
if Currency then
Currency.Value = tostring(en.convert(Currency.Value) + SpinModule.Spin.Rewards[SpinReward].Amount)
else
warn(SpinModule.Spin.Rewards[SpinReward].Reward.." not found in leaderstats")
end
end
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerRemoved)
if game:GetService("RunService"):IsStudio() then
Players.PlayerRemoving:Connect(StudioSave)
end
SpinEvent.OnServerEvent:Connect(SpinEventFire)
and finally this is my module script:
local module = {
["Spin"] = {
["SpinTime"] = 5,
["SpinTimeForReward"] = 60*5,
["Rewards"] = {
["Reward1"] = {
["Reward"] = "Cash",değiştir
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(115, 255, 131),
["Rarity"] = 34,
},
["Reward2"] = {
["Reward"] = "Cash",
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(115, 255, 131),
["Rarity"] = 25,
},
["Reward3"] = {
["Reward"] = "Cash",
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(115, 255, 131),
["Rarity"] = 17,
},
["Reward4"] = {
["Reward"] = "Cash",
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(115, 255, 131),
["Rarity"] = 15,
},
["Reward5"] = {
["Reward"] = "Tokens",-- leaderstats.Gems kendi elmas/para birimine göre değiştir
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(199, 108, 255),
["Rarity"] = 5,
},
["Reward6"] = {
["Reward"] = "Tokens",
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(199, 108, 255),
["Rarity"] = 3,
},
["Reward7"] = {
["Reward"] = "Tokens",
["Amount"] = 2500000000000000000,
["TextColor"] = Color3.fromRGB(199, 108, 255),
["Rarity"] = 1,
},
},
},
}
module.getRandomReward = function()
local totalChance = 0
for _, rewardData in pairs(module.Spin.Rewards) do
totalChance = totalChance + rewardData.Rarity
end
local randomValue = math.random() * totalChance
local accumulatedChance = 0
for rewardName, rewardData in pairs(module.Spin.Rewards) do
accumulatedChance = accumulatedChance + rewardData.Rarity
if randomValue <= accumulatedChance then
return rewardName
end
end
return nil
end
return module
Any help is hugely appreciated