Value = workspace.Partscan.Sugar.Value if workspace.Partscan.Sugar.Value == 0 then workspace.Partno.SurfaceGui.Frame.Sugar.Text = "Sugar 0/1" elseif workspace.Partscan.Sugar.Value == 1 then workspace.Partno.SurfaceGui.Frame.Sugar.Text = "Sugar 1/1" end
The Text works when there's no sugar, but when sugar is added, it doesn't function. Not sure what to do.
Can someone please help me? thanks!
Why your code only works once
It is only ran once so the 1st result will always be the value of sugar.
What you need is to add a changed event so when the value of sugar changes the Gui is updated.
local sugarObj = game.Workspace.Partscan.Sugar sugarObj .Changed:connect(function(newVal) -- this is the changed event for the sugar which gives the new value as a parameter -- set the new value game.Workspace.Partno.SurfaceGui.Frame.Sugar.Text = "Sugar " .. tostring(newValue) .. "/1" end)
This is only an example, hope this helps
How to improve this script
Currently there are no checks to there is a possibility of parts being nil
Hey Kitorari,
Ok so basically what you want to do is use game.Workspace, it will help. And you are using numbers with integers (but that isnt the real problem I dont think).
Value = tonumber(game.Workspace.Partscan.Sugar.Value) SugarLabel = game.Workspace.Partno.SurfaceGui.Frame.Suger if Value == 0 then SugarLabel.Text = "Sugar 0/1" elseif Value == 1 then SugarLabel.Text = "Sugar 1/1" end
If this works, accept answer, it helps both of us