I’m not sure why I’m getting this error, I saw another post saying to use the GetPropertyChangedSignal to detect if a value has changed, but right now it only results in an error.
local mValue = dmgMultiplier.Value
local dmg = 10
mValue:GetPropertyChangedSignal("mValue"):Connect(function()
dmg = dmg * mValue
end)
Edit: Also here’s where I get the DamageMultiplier from:
local DmgIncrease = game.ReplicatedStorage.DmgIncrease
local dmgMultiplier = {Value = 1}
DmgIncrease.Event:Connect(function()
dmgMultiplier.Value = 10
end)
return dmgMultiplier
it’s probably because you’re using “mValue” instead of the actual property of “Value” within mValue.GetPropertyChangedSignal and setting mValue to “dmgMultiplier.Value” and not “dmgMultiplier”. That’s if this is an IntValue instance.
As others have pointed out, you are indexing the actual value of the object, not the object itself. At the time of writing, the other solutions presented all have an issue that would prevent them from working.
You are repeatedly multiplying the same value which would cause exponential growth. For example, if dmg = 10 and you changed dmgMultiplier.Value = 2, you would have dmg = 20. But then, if you changed dmgMultiplier.Value = 3 you would have dmg = 60, not dmg = 30!
For a Value object, you can also just use the .Changed event.
Try this:
local BASE_DMG = 10
local dmg = BASE_DMG * dmgMultiplier.Value
dmgMultiplier.Changed:Connect(function()
dmg = BASE_DMG * dmgMultiplier.Value
end
In most cases, you cannot call :GetPropertyChangedSignal or connect to .Changed on a table value. Consider using the Value object instead for your desired functionality
local dmgMultiplier = Instance.new("NumberValue")
-- maybe set dmgMultiplier.Parent if you want other scripts to access it
dmgMultiplier.Value = 1
Yooo Bereza I’m a fan of your games! Sorry to everyone that I haven’t posted about where I get my dmgMultiplier from earlier, but I do want the other scripts to be able to access the dmgMultiplier value and I think you said that I should set a parent for the value. Could I ask where I set the parent to?
Since it’s a module script you don’t have to set the parent for it to be accessible through require. Setting it’s parent would let other scripts access the value via object path i.e. game.ServerStorage.YourModuleScript.NumberValue. For script related values it is probably best to parent them to the script.
If you want the value to be accessed by both client and server scripts, you can put it in game.ReplicatedStorage. If you only want it to be accessed by the server, you can put it in game.ServerStorage.
Thank you guys, I really don’t mean to be a drag, I might be misunderstanding something but as of the moment I’m still getting the same error. I have tried the solutions on the first few replies, however I still have gotten the error. For Bereza’s response, I have tried making a new instance along with setting the name of it and parenting the instance to the ReplicatedStorage but I got the same result, I then tried creating a NumberValue in the Replicated storage but that still didn’t work. For Gert’s response, thanks, I was just replying to Bereza (hi again, I really didn’t expect to stumble across another error so soon), and for Forummer’s reply, using the Changed event still created the same error (“attempt to index number with ‘Changed’”).