To make it short, i have a script that does damage at some point, Let's say in the tool i have a IntValue with a value of 5 called Bob
Bob=script.Parent.Bob.Value
in the script, the damage value is
Dmg = 0.5*Bob
So the problem is, It does calculate 0.5*5 , But if the value changes, it will still calculate the base value of Bob and not the new value. How can i make the script check what the value is more than one time?
Thanks already anyone willing to help.
You are storing a value from IntValue into the Bob variable. That variable will never change unless you change it yourself. To make the variable change with the value, you have to store the IntValue itself, and then get the Value every time you need it, like this:
Bob = script.Parent.Bob Dmg = 0.5*Bob.Value wait(2) -- If Bob's Value changes in these 2 seconds, the variable below will have a different value than the variable above Dmg = 0.5*Bob.Value
If you need any more help, make sure to leave a comment.
EDIT
If you want the Dmg
variable to change every time the Bob
s Value changes, you can bind an event, like this:
Bob = script.Parent.Bob Dmg = 0.5*Bob.Value Bob.Changed:connect(function(dmg) Dmg = 0.5 * dmg end)
That Changed
you see up there is an event that every object has, it listens for any changes in the object's properties.
IntValue object has a Changed
event which passes the new value (I called it dmg) to the function bound to it.