How do i fix attempt to index number with 'Changed'?

I keep getting this error and im not really sure what it means, can someone help me?

 local player = game.Players.LocalPlayer
local CurrentExp = player:WaitForChild("leaderstats").Exp.Value
local MaxExp = player:WaitForChild("leaderstats").ExpToLevel.Value

local Gui = script.Parent
local Exterior = Gui:WaitForChild("BackFrame")
local label = Gui:WaitForChild("TextLabel")
local Bar = Gui:WaitForChild("Expbar")

CurrentExp.Changed:Connect(function() --This is where the problem is
	if CurrentExp >= MaxExp then
		Bar.Size = UDim2.new(CurrentExp/MaxExp,0,1,0)
		wait(0.5)
		CurrentExp = 0
		Bar.Size = UDim2.new(CurrentExp/MaxExp,0,1,0)
	else
		Bar.Size = UDim2.new(CurrentExp/MaxExp,0,1,0)
	end
end)

Bar.Size = UDim2.new(CurrentExp/MaxExp,0,1,0)

1 Like

Turn that line to

local CurrentExp = player:WaitForChild("leaderstats").Exp

And every time you mention CurrentExp, change it to CurrentExp.Value Except for the one with .Changed

But when i did that the problem still kept happening

Show the code so I can see what happened

Oh wait now its working never mind thanks, now its just tweening problems

Everytime there is CurrentExp, change it toCurrentExp.Value except for the one with .changed, so soemthing like

local player = game.Players.LocalPlayer
local CurrentExp = player:WaitForChild("leaderstats").Exp
local MaxExp = player:WaitForChild("leaderstats").ExpToLevel

local Gui = script.Parent
local Exterior = Gui:WaitForChild("BackFrame")
local label = Gui:WaitForChild("TextLabel")
local Bar = Gui:WaitForChild("Expbar")

CurrentExp.Changed:Connect(function()
	if CurrentExp.Value >= MaxExp.Value then
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
		wait(0.5)
		CurrentExp.Value = 0
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
	else
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
	end
end)

Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)

Edit: Did the change to MaxExp too

1 Like

Okay so, do what @EmbatTheHybrid said, but additionally change the line CurrentExp >= MaxExp then to CurrentExp.Value >= MaxExp.Value

Oh come on! I am on ipad so I can’t type as fast lol

When i did that it said attempt to index number with ‘Value’

Haha, I just realised the coincidence that as soon as I editted it, you sent your message

Use the code I provided that I edited where I fixed up the code

1 Like

Yep, I am not as fast on Ipad than I am on pc.

Screen Shot 2021-03-09 at 6.53.07 AM

You probably used an older unedited version of the code I sent since it should work, copy and paste it again

thanks it works now

Anytime! I recommend you mark my post as the solution incase anyone stumbles upon this post and needs a solution too! IF you have anymore questions don’t be afraid to ask!