Hello, I’m currently making a statistics system where you can upgrade your power, endurance, stamina, and other stats. I have recently found out about “Attributes” and decided to use it.
This issue is applicable to every attribute excluding skill points. The Jump, Max Power, Delay, and Glide stats are detected on the client but only prints their starting value, not their value after the changes.
Server Script:
Players.PlayerAdded:Connect(function(Player)
local statFolder = Instance.new("Folder")
statFolder.Name = "Stats"
statFolder.Parent = Player
statFolder:SetAttribute("Jump", 0)
statFolder:SetAttribute("Delay", 0)
statFolder:SetAttribute("Glide", 0)
statFolder:SetAttribute("MaxPower", 8)
statFolder:SetAttribute("Endurance", 10)
statFolder:SetAttribute("SkillPoints", 20)
end)
statEvent.OnServerEvent:Connect(function(plr, input, value)
local StatFolder = plr:WaitForChild("Stats")
local function limit(stat, name, val, val2)
if stat > val then stat = StatFolder:SetAttribute(name, val) elseif stat < val2 then StatFolder:SetAttribute(name, val2) end
end
if input == "Jump" then
StatFolder:SetAttribute("Jump", value)
limit(StatFolder:GetAttribute("Jump"), "Jump", 6, 0)
elseif input == "Power" then
StatFolder:SetAttribute("MaxPower", value)
limit(StatFolder:GetAttribute("MaxPower"), "MaxPower", 17, 8)
elseif input == "SkillPoints" then
StatFolder:SetAttribute("SkillPoints", StatFolder:GetAttribute("SkillPoints") + value)
limit(StatFolder:GetAttribute("SkillPoints"), "SkillPoints", 20, 0)
elseif input == "Endurance" then
StatFolder:SetAttribute("Endurance", value)
limit(StatFolder:GetAttribute("Endurance"), "Endurance", 15, 10)
elseif input == "Delay" then
StatFolder:SetAttribute("Delay", value)
limit(StatFolder:GetAttribute("Delay"), "Delay", 0.925, 0)
elseif input == "Glide" then
StatFolder:SetAttribute("Glide", value)
limit(StatFolder:GetAttribute("Glide"), "Glide", 0.35, 0)
end
end)
Here is a part of a LocalScript that handles power. This is also where the issue happens, the print(maxPower) only prints 8 even when it detects attribute changes and increases. This also happens with the Jump, Glide, and Delay stats.
statFolder:GetAttributeChangedSignal("MaxPower"):Connect(function()
print(maxPower) -- always prints 8 even if the attribute is increasing.
Label.Text = power.Value.." / "..maxPower
Bar.Size = UDim2.new(power.Value/maxPower, 0, 1, 0)
end)
If I am doing something wrong, please tell me.
ADDITIONAL INFORMATION:
I have also tried attributes for detecting the player’s tilt type, spin value, ball type, and they all seem to work and become recognized.