You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? a system that shows my strength/capacity
What is the issue?
but i feel like the while wait() is just a constant loop which can cause lag
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I have a coins display that works fine heres the code
local NumberAnimation = require(game.ReplicatedStorage.NumberAnimation)
local player = game:GetService("Players").LocalPlayer
local textLabel = script.Parent
local coins = player.leaderstats.Gems
local coinsNumberAnimation = NumberAnimation.new(textLabel, coins, {
Style = "Tween",
Time = 1,
EasingStyle = "Quad",
EasingDirection = "InOut",
Abbreviate = true
})
coinsNumberAnimation:SetPrefix("")
coinsNumberAnimation:Start()
But idk how to implement this code for my strength code which is this
local player = game.Players.LocalPlayer
local module = require(game.ReplicatedStorage.Abbreviations)
local id = 24229502
while task.wait() do
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
script.Parent.Text = module.abbreviate(player.leaderstats.Strength.Value).." / "..(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
else
script.Parent.Text = module.abbreviate(player.leaderstats.Strength.Value).." / "..module.abbreviate(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
end
end
local players = game:GetService("Players")
local player = players.LocalPlayer
local strength = player.leaderstats.Strength
local module = require(game.ReplicatedStorage.Abbreviations)
local id = 24229502
strength.Changed:Connect(function(value)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
script.Parent.Text = module.abbreviate(value).." / "..(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
else
script.Parent.Text = module.abbreviate(value).." / "..module.abbreviate(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
end
end)
I haven’t read through a lot of your code, but couldn’t you just call the function upon joining?
local function updateValue(value)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
script.Parent.Text = module.abbreviate(value).." / "..(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
else
script.Parent.Text = module.abbreviate(value).." / "..module.abbreviate(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
end
end
strength.Changed:Connect(updateValue)
updateValue(strength.Value) -- Idk if the value would have initialized by now
all you would need to do is set it once after the game has loaded the data.
you can try this code:
local players = game:GetService("Players")
local player = players.LocalPlayer
local strength = player:WaitForChild("leaderstats"):WaitForChild("Strength")
local module = require(game.ReplicatedStorage.Abbreviations)
local id = 24229502
if strength.Value ~= 0 then
task.wait()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
script.Parent.Text = module.abbreviate(value).." / "..(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
else
script.Parent.Text = module.abbreviate(value).." / "..module.abbreviate(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
end
end
strength.Changed:Connect(function(value)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
script.Parent.Text = module.abbreviate(value).." / "..(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
else
script.Parent.Text = module.abbreviate(value).." / "..module.abbreviate(player:WaitForChild("BackpackShop"):WaitForChild("Capacity").Value)
end
end)