I'm trying to make a grading system, and when I click "calculate" it always says "FAILED" and "0/100" and the value has not changed. Could use some help.
frame = script.Parent.Parent score = frame.scoreval.Value inter = frame.intersectionc.checked.Value park = frame.parkingc.checked.Value sharp = frame.sharpc.checked.Value stop = frame.stopc.checked.Value grammar = frame.grammarc.checked.Value wide = frame.widec.checked.Value function click() script.Parent.Text = "CALCULATING" if inter == true then score = score + 20 end wait(0.01) if park == true then score = score + 20 end wait(0.01) if sharp == true then score = score + 10 end wait(0.01) if stop == true then score = score + 15 end wait(0.01) if grammar == true then score = score + 20 end wait(0.01) if wide == true then score = score + 10 end script.Parent.Text = "CALCULATE" local finalscore = score if finalscore >= 80 then frame.pass.Text = "PASSED" frame.score.Text = finalscore.."/100" elseif finalscore < 80 then frame.pass.Text = "FAILED" frame.score.Text = finalscore.."/100" end end script.Parent.MouseButton1Click:connect(click)
You're defining all of the values outside of the function! This way then they will never change and will always return false! You need to not index the Value
property when defining them, and then index the Value
property when checking them(:
local frame = script.Parent.Parent local score = frame.scoreval local inter = frame.intersectionc.checked local park = frame.parkingc.checked local sharp = frame.sharpc.checked local stop = frame.stopc.checked local grammar = frame.grammarc.checked local wide = frame.widec.checked function click() script.Parent.Text = "CALCULATING" if inter.Value == true then score = score + 20 end wait(0.01) if park.Value == true then score = score + 20 end wait(0.01) if sharp.Value == true then score = score + 10 end wait(0.01) if stop.Value == true then score = score + 15 end wait(0.01) if grammar.Value == true then score = score + 20 end wait(0.01) if wide.Value == true then score = score + 10 end script.Parent.Text = "CALCULATE" local finalscore = score.Value if finalscore >= 80 then frame.pass.Text = "PASSED" frame.score.Text = finalscore.."/100" elseif finalscore < 80 then frame.pass.Text = "FAILED" frame.score.Text = finalscore.."/100" end end script.Parent.MouseButton1Click:connect(click)
To clarify Goulstem's answer a bit, your first issue was that you made a variable equal to an object's property. When you do this, no reference to the object itself is retained. This means, in your case, that the variable will be just a number, and will not change if the property changes later.
So, now that's fixed, but now you have another issue. score
isn't a number anymore -- it's an object. You would therefore need to write score.Value
each time you want to use its value.
However, I would recommend not storing the score inside an object. If you just make it a variable, it will be much harder for hackers to change.
local score = 0
will work fine, and will be much safer.