I am making a leveling system, and I have a intvalue under the player that has experience. But even if i continually print it, it will say the value of experience is 0 even though i changed it to 1. Here is my script:
game.Players.PlayerAdded:Connect(function(player)
local levelInfo = Instance.new("Folder")
levelInfo.Name = "LevelsInfo"
levelInfo.Parent = player
local level = Instance.new ("IntValue")
level.Name = "Level"
level.Value = 1
level.Parent = levelInfo
local exp = Instance.new ("IntValue")
exp.Name = "Experience"
exp.Value = 0
exp.Parent = levelInfo
local xpNeeded =50* level.Value
exp.Changed:Connect(function(newExp)-- this always thinks it is 0 even though i change it
if newExp >= xpNeeded then
level.Value += 1
exp.Value -= xpNeeded
xpNeeded = 50*level.Value
end
end)
end)
Instead of using newExp, Use exp.Value. Another thing i recommend you doing is changing the exp.Changed Event to exp:GetPropertyChangedSignal("Value").
I will try that, what are the differences between .changed and getpropertychagned signal?
edit: never mind, it is just that it doesnt even know that the value is changed. For example:
if I put I loop in it that prints the value of exp every second, it should print 0 until i change it, but once i change it it still prints 0
GetPropertyChangedSignal will only fire once the certain Value is changed. Meanwhile the Changed Event will fire whenever any property of the Instance gets modified.
It just doesnt think it changed for some reason, even though i changed it. For example:
if I put I loop in it that prints the value of exp every second, it should print 0 until i change it, but once i change it it still prints 0