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

How to solve "attempted to call field "Value" (a number value)" error?

This script is supposed to display the score on a practical test out of 8, it does the theory score fine but throws an error when doing the Practical Result. I've made sure that PracticalResult does have a value inside game.Players.Local player and yet I get the error: attempted to call field "Value" (a number value)

Help is much appreciated MD


function onClick()
	PracScore = game.Players.LocalPlayer.PracticalScore
	script.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.OverallResult.Visible = true
	script.Parent.Parent.Parent.OverallResult.TheoryResult.Text = "You scored: "..script.Parent.Parent.Parent.Score.Value.." out of 10"
	script.Parent.Parent.Parent.OverallResult.PracticalResult.Text = "You scored: "..PracScore.Value " out of 8" -- error occurs here

end

script.Parent.MouseButton1Click:connect(onClick)

1 answer

✓ Accepted answer

When you insert a value into a string, you need the periods on both sides.

Line 6:

script.Parent.Parent.Parent.OverallResult.PracticalResult.Text = "You scored: "..PracScore.Value.." out of 8"

3 comments

0

Better?

0

The cause of this syntax error being "calling" is because the parenthesis are optional around function arguments if the args are literal tables or strings. For example, print "hi" works without parenthesis. In this case, you have PracScrore.Value "out of 8" which syntactically is the same as the previous snippet--hence, calling a number (.Value).

0

Aha, thanks :)

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