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

Number Values not able to be edited?

Asked by 10 years ago

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.

01Data = script.Parent.Parent.Parent.PlayerData
02 
03script.Parent.skillAccuracy.TextButton.MouseButton1Down: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
08end)
09 
10script.Parent.skillDefense.TextButton.MouseButton1Down: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
15end)
View all 46 lines...

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

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

1print {}
2table: 0xcbb8f0
3 
4print "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!

0
I originally had variables, but I was having a slight problem with the PlayerGui earlier. MisaMiner 50 — 10y
Ad

Answer this question