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

The value error does not pop up in-studio but, it does in-game?

Hey, guys so I posted a question about this not too long ago someone answered it and help me out thank God but, now I ran into another problem... I fixed my code and all however, in-game the same value error keeps popping up.... Here are the script and Error and yes this game uses FIlteringEnabled my script is inside of a ImageLabel and it's a LocalScript and it's activated by a RemoteEvent.

ERROR:

08:18:44 - Players.KingLoneCat.PlayerGui.StatsGui.XP Gui.ImageLabel.LocalScript:7: attempt to call field 'Value' (a number value)

08:18:44 - Stack Begin 00:19:48.961 - Script 'Players.KingLoneCat.PlayerGui.StatsGui.XP Gui.ImageLabel.LocalScript', Line 7

08:18:44 - Stack End

SCRIPT:

local player = script.Parent.Parent.Parent.Parent.Parent
local stats = player:WaitForChild("Stats")
local xp = stats:WaitForChild("XP")
local level = stats:WaitForChild("Level")
local defense = stats:WaitForChild("Defense")
local tlabel = script.Parent.Parent:WaitForChild("TextLabel")
tlabel.Text = "XP: "..xp.Value.."/"..xp.MaxValue
xp.Changed:connect(function()
	if xp.Value >= xp.MaxValue and level.Value ~= 15 then
	level.Value = level.Value + 1
	defense.Value = defense.Value + 10
	xp.MaxValue = xp.MaxValue + 20
	xp.Value = 0
	tlabel.Text = "XP: "..xp.Value.."/"..xp.MaxValue
	else
	tlabel.Text = "XP: "..xp.Value.."/"..xp.MaxValue
	script.Parent:TweenSize(UDim2.new(xp.Value/xp.MaxValue,0,.05,0), "InOut", "Quad", .2, true)
	end
end)

Thank you for reading this question and I hope someone can help!

~~ KingLoneCat

2 comments

0

what is object xp and how can is sore both both xp.Value and xp.MaxValue?

0

XP is an IntConstrainedValue

1 answer

There is no such thing as a MaxValue on a NumberValue. If you want to set a max, just add in another variable and set it to your preferred number.

Here is the new script:

local player = script.Parent.Parent.Parent.Parent.Parent
local stats = player:WaitForChild("Stats")
local xp = stats:WaitForChild("XP")
local level = stats:WaitForChild("Level")
local defense = stats:WaitForChild("Defense")
local tlabel = script.Parent.Parent:WaitForChild("TextLabel")
maxValue = 100 --variable used to represent the max number you can have

tlabel.Text = "XP: "..xp.Value.."/"..maxValue

xp.Changed:connect(function()
    if xp.Value >= maxValue and level.Value ~= 15 then
    	level.Value = level.Value + 1
    	defense.Value = defense.Value + 10
   		maxValue = maxValue + 20
    	xp.Value = 0
    	tlabel.Text = "XP: "..xp.Value.."/"..maxValue
    else
    	tlabel.Text = "XP: "..xp.Value.."/"..maxValue
    	script.Parent:TweenSize(UDim2.new(xp.Value/maxValue,0,.05,0), "InOut", "Quad", .2, true)
    end
end)


1 comment

0

I was using an IntConstrainedValue... So it had a MaxValue and a Value... Check it out it's pretty cool.

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