Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Grading system not working?

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)

2 comments

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.

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%

2 answers

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)

4 comments

0

Dang it... You posted before me... I'll just delete mine...

0

I get "attempt to compare number with userdata" on the "if finalscore >= 80 then" line.

0

Line numbers are wonderful

0

Fixed it

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.

5 comments

0

boommm

0

Doesn't work. I PMed you on ROBLOX what I have now as putting the code in a comment would not be ideal.

0

What exactly doesn't work? any output?

0

No output, it does the same thing as before. "FAILED" and "0/100" score.

0

Then the values must not be true.

This discussion is preserved as it was. New answers, comments, and votes are closed.