Hey! I want to make a backpack system so when the ‘currency’ value stops when it’s equal to the ‘backpack’ capacity. But I can’t understand how the value can go further then 10 because of the if statement should only go through if Shine2 is less or equal to 10. But the value won’t stop adding.
This is what’s happening
And this is the script a have made
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Shine = leaderstats:FindFirstChild("Shine")
local Backpack = script.Parent.Parent.Value
local Shine2 = Shine.Value
if Shine2 <= 10 then
script.Parent.Text = Shine.Value.."/".. Backpack.Value
Shine.Changed:connect(function()
script.Parent.Text = Shine.Value.."/".. Backpack.Value
end)
end
I have just tried scripting some more but I couldn’t fix it.
Shine2 = Shine.Value will return the current value of Shine, and will not update when it is changed. You already have the Shine IntValue with the variable Shine, so compare it’s current value agaisnt the max value.
local Shine = leaderstats:FindFirstChild("Shine") -- keep this. remove Shine2
Shine.Value < 10 then
-- stuff
end
´´´lua
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild(“leaderstats”)
local Shine = leaderstats:FindFirstChild(“Shine”)
local Backpack = script.Parent.Parent.Value
if Shine < 10 then
script.Parent.Text = Shine.Value…“/”… Backpack.Value
Shine.Changed:connect(function()
script.Parent.Text = Shine.Value…“/”… Backpack.Value
end)
end
´´´
I just noticed that your Shine.Changed function is inside of the Shine check. This would mean that whats happening is that your script will check the value one time when the script starts, but never again when the value changes.
Replace
with
script.Parent.Text = Shine.Value.."/".. Backpack.Value
Shine.Changed:Connect(function()
if Shine.Value < 10 then
script.Parent.Text = Shine.Value.."/".. Backpack.Value
end
end)