I have a function in my leaderstats script that says when the exp is changed it should print changed but it does not.
Code:
Exp.Changed:Connect(function()
print("Changed")
end)
Full Code:
game.Players.PlayerAdded:Connect(function(player)
game.Lighting.Blur.Enabled = true
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local values = Instance.new("Folder", player)
values.Name = "Values"
local gold = Instance.new("IntValue", leaderstats)
gold.Name = "Gold"
local mana = Instance.new("IntValue", values)
mana.Name = "Mana"
mana.Value = 50
local maxMana = Instance.new("IntValue", values)
maxMana.Name = "MaxMana"
maxMana.Value = 50
local Level = Instance.new("NumberValue",leaderstats)
Level.Name = "Level"
Level.Value = 1
local Exp = Instance.new("NumberValue",values)
Exp.Name = "Exp"
Exp.Value = 0
local RequiredExp = Instance.new("NumberValue",values)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Level.Value*100
local class = Instance.new("StringValue", values)
class.Name = "Class"
class.Value = "N/A"
Exp.Changed:Connect(function()
print("Changed")
end)
end)
1 Like
Volieb
(Vinny)
March 5, 2022, 3:05am
#2
Make sure the value is actually being created (I’m sure it is).
The only other thing I can think of is that the value is not actually changing. Make sure it is changing on the SERVER and not just the client, as your script will not detect changes on the client.
2 Likes
I have spent an hour on this. The script is a server script in server script service controlling the leaderstats but it still does not fire in any other script I have tried
Volieb
(Vinny)
March 5, 2022, 3:15am
#4
Make sure the value is actually being changed. While testing, you can use the server view option to see from the server’s POV. Let me know your results.
Forummer
(Forummer)
March 5, 2022, 1:19pm
#6
That’s a really bad practice, .Changed
does work for NumberValue instances, as you can see here.
local numberValue = Instance.new("NumberValue")
numberValue.Changed:Connect(function(number)
print(number)
end)
numberValue.Value = math.pi
4 Likes
Forummer
(Forummer)
March 5, 2022, 1:22pm
#7
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out.
Tthere are several ways to create a ROBLOX object in Lua:
local obj = Instance.new(‘type’); fill obj fields
local obj = Instance.new(‘type’, parent); fill obj fields
local obj = util.Create(‘type’, { field1 = value1, … })
If you care at all about performance, please only use the first option - I wi…
Parent the number value instance after you have created a RBXScriptConnection object from its Changed
RBXScriptSignal object.
5 Likes