In the output I am getting such errors as:
Players.Player1.PlayerGui.ScreenGui.framePage2.frameSkills.:40: attempt to call field 'Value' (a number value)
&
Players.Player1.PlayerGui.ScreenGui.framePage2.frameLabel.S:2: attempt to call field 'Value' (a number value)
I am just editing values in my script, but these error always appear.
01 | Data = script.Parent.Parent.Parent.PlayerData |
02 |
03 | script.Parent.skillAccuracy.TextButton.MouseButton 1 Down:connect( function () |
04 | if script.Parent.valuePoints.Value ~ = 0 then |
05 | Data.SkillData.dataAccuracy.Value = Data.SkillData.dataAccuracy.Value + 1 |
06 | script.Parent.valuePoints.Value = script.Parent.valuePoints.Value - 1 |
07 | end |
08 | end ) |
09 |
10 | script.Parent.skillDefense.TextButton.MouseButton 1 Down:connect( function () |
11 | if script.Parent.valuePoints.Value ~ = 0 then |
12 | Data.SkillData.dataDefense.Value = Data.SkillData.dataDefense.Value + 1 |
13 | script.Parent.valuePoints.Value = script.Parent.valuePoints.Value - 1 |
14 | end |
15 | end ) |
If someone were to analyse this code and find out what I am doing wrong, I would love it! Just a note to self, I will never use values like this again
This is because of a weirdness of Lua that I don't like.
What you're doing is basically right.
Note that it's saying it's trying to call the Value. That means it's treating it like a function. But, if you look, it doesn't look like you are: there's no parenthesis after it!
That's because Lua let's you call functions without the parenthesis if the thing following it is a string or table literal.
E.g.
1 | print { } |
2 | table: 0 xcbb 8 f 0 |
3 |
4 | print "hi" |
5 | -- hi |
In my opinion this is a dangerous feature because it results in problems like you are having now.
You have Data.SkillData.dataStrngth.Value ""
without a ..
before the ""
. So it thinks you're trying to use .Value
as a function, which it isn't.
Put a ..
in and it will make that error go away.
At the same time, doing .. ""
is also pointless since the thing to the left is already a string, so you can just do without it.
I would probably suggest coming up with variables to point to objects making these statements a lot shorter!