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

Number Values not able to be edited?

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.

Data = script.Parent.Parent.Parent.PlayerData

script.Parent.skillAccuracy.TextButton.MouseButton1Down:connect(function()
	if script.Parent.valuePoints.Value ~= 0 then
		Data.SkillData.dataAccuracy.Value = Data.SkillData.dataAccuracy.Value +1
		script.Parent.valuePoints.Value = script.Parent.valuePoints.Value -1 
	end
end)

script.Parent.skillDefense.TextButton.MouseButton1Down:connect(function()
	if script.Parent.valuePoints.Value ~= 0 then
		Data.SkillData.dataDefense.Value = Data.SkillData.dataDefense.Value +1
		script.Parent.valuePoints.Value = script.Parent.valuePoints.Value -1 
	end
end)

script.Parent.skillMagic.TextButton.MouseButton1Down:connect(function()
	if script.Parent.valuePoints.Value ~= 0 then
		Data.SkillData.dataMagic.Value = Data.SkillData.dataMagic.Value +1
		script.Parent.valuePoints.Value = script.Parent.valuePoints.Value -1 
	end
end)

script.Parent.skillSpeed.TextButton.MouseButton1Down:connect(function()
	if script.Parent.valuePoints.Value ~= 0 then
		Data.SkillData.dataSpeed.Value = Data.SkillData.dataSpeed.Value +1
		script.Parent.valuePoints.Value = script.Parent.valuePoints.Value -1 
	end
end)

script.Parent.skillStrength.TextButton.MouseButton1Down:connect(function()
	if script.Parent.valuePoints.Value ~= 0 then
		Data.SkillData.dataStrength.Value = Data.SkillData.dataStrength.Value +1
		script.Parent.valuePoints.Value = script.Parent.valuePoints.Value -1 
	end
end)


while true do
	script.Parent.skillAccuracy.TextLabel.Text = "Accuracy: " .. Data.SkillData.dataAccuracy.Value ""
	script.Parent.skillDefense.TextLabel.Text = "Defense: " .. Data.SkillData.dataDefense.Value ""
	script.Parent.skillMagic.TextLabel.Text = "Magic: " .. Data.SkillData.dataMagic.Value ""
	script.Parent.skillSpeed.TextLabel.Text = "Speed: " .. Data.SkillData.dataSpeed.Value ""
	script.Parent.skillStrength.TextLabel.Text = "Strength: " .. Data.SkillData.dataStrngth.Value ""
	wait()
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

1 answer

✓ Accepted answer

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.

print {}
table: 0xcbb8f0

print "hi"
-- 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!

1 comment

0

I originally had variables, but I was having a slight problem with the PlayerGui earlier.

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