Hello guys
I’m working on the button simulator game and creating a script about updating all stats’s Multiplier when players join and other stats that are changed. the script is in the ServerScriptService
but there’s a problem, If I joined the game, this script would be affected by only one stats
and working weirdly
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local StatList = require(Modules:WaitForChild("StatList"))
local StatResources = ReplicatedStorage:WaitForChild("StatsResources")
local function UpdateMultiplier(player)
local StatFolder = player:WaitForChild("Stats")
for _, statData in ipairs(StatList) do
local StatName = statData[2]
local StatType = statData[3]
local StatMultiplierValues = StatResources:FindFirstChild(StatType, true):FindFirstChild(StatName, true):WaitForChild("Boosts"):GetChildren()
for _, StatMValues in ipairs(StatMultiplierValues) do
local StatThatEffectMultiplier = StatMValues.Parent.Parent
local RealStatMultiplierValues = StatFolder:WaitForChild(StatMValues.Name)
local RealStatThatEffectMultiplier = StatFolder:WaitForChild(StatThatEffectMultiplier.Name)
if RealStatMultiplierValues.Multiplier.Value > 0 then
RealStatMultiplierValues.Multiplier.Value = RealStatMultiplierValues.Multiplier.Value * (StatMValues.Value * RealStatThatEffectMultiplier.Value.Value)
elseif RealStatMultiplierValues.Multiplier.Value == 0 then
RealStatMultiplierValues.Multiplier.Value = 1
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
local statsFolder = player:WaitForChild("Stats")
for _, statData in ipairs(StatList) do
local statName = statData[2]
local statValue = statsFolder:WaitForChild(statName):WaitForChild("Value")
statValue.Changed:Connect(function()
if statData[3] ~= "Basic" then
UpdateMultiplier(player)
end
end)
end
UpdateMultiplier(player)
end)
and this is Statlist ModuleScript
return {
--{"StatCode""StatName", "StatType", "StatColor3", StatBadgeID, IsStatResetWhenBought?}
--[v1] [v2] [v3] [v4] [v5] [v6]
-- Basic Stats --
{1, "Cash", "Basic", Color3.fromRGB(26, 255, 0), 0, false};
-- Normal Stats --
{2, "Multiplier", "Normal", Color3.fromRGB(255, 42, 0), 0, false};
{3, "Rebirth", "Normal", Color3.fromRGB(0, 255, 255), 0, true};
{4, "Dirt", "Normal", Color3.fromRGB(139, 57, 19), 0, true};
{5, "Stone", "Normal", Color3.fromRGB(139, 139, 139), 0, true};
-- Secret Stats --
-- Rng Stats --
-- Special Stats --
{100001, "VioletFragment", "Special", Color3.fromRGB(70, 22, 124), 0, false};
}
this is the StatsResorcesFolder in ReplicatedStorage
and this is statsFolder in Player (When I joined the game)