Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Grading system not working?

Asked by
shayner32 478 Trusted Moderation Voter
9 years ago

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)
0
You can get scores by, dividing the number of answers correct by the number of questions on the test. Then you multiply that number by the score. For example, you got 48/60 on a test. The max score is 600. The score you got is 480. EzraNehemiah_TF2 3552 — 9y
0
You could also do this by dividing the possible correct by the number they got correct then multiply by 100. If it was 40/50 point, you would do 40 Divided by 50, and get .8, then multiply that by 100, and it comes out to 80% dyler3 1510 — 9y

2 answers

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your Problem

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(:


Code

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)
0
Dang it... You posted before me... I'll just delete mine... EzraNehemiah_TF2 3552 — 9y
0
I get "attempt to compare number with userdata" on the "if finalscore >= 80 then" line. shayner32 478 — 9y
0
Line numbers are wonderful unmiss 337 — 9y
0
Fixed it Goulstem 8144 — 9y
Ad
Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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.

0
boommm unmiss 337 — 9y
0
Doesn't work. I PMed you on ROBLOX what I have now as putting the code in a comment would not be ideal. shayner32 478 — 9y
0
What exactly doesn't work? any output? Perci1 4988 — 9y
0
No output, it does the same thing as before. "FAILED" and "0/100" score. shayner32 478 — 9y
0
Then the values must not be true. Perci1 4988 — 9y

Answer this question