Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Problem making a script verify a value constantly?

Asked by 9 years ago

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.

1 answer

Log in to vote
1
Answered by 9 years ago

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 Bobs 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.

0
Yep ^ Vezious 310 — 9y
0
That helps , But would there be a way to loop that very part within the script? The IntValue's Value can change at anytime during various circumstances, as far as i can tell, what you just posted, would check once after 2 seconds. RedemptedNutella 15 — 9y
0
Wait, what do you mean by that? Dmg is only a variable. Do you have another IntValue called Dmg? Or are you using that Dmg variable somewhere else in the same Script? LetThereBeCode 360 — 9y
0
The Dmg Variable calculated in the script is used later in the same script to define the ammount of damage dealt along with the rest of the code. RedemptedNutella 15 — 9y
View all comments (12 more)
0
I update my code to fit your needs. LetThereBeCode 360 — 9y
0
If that helps, a fix i have tought about was to make the Calculation a "while true do" While it did work, the script would be stuck on the loop and not proceed on pretty much breaking the tool. RedemptedNutella 15 — 9y
0
Try my edited code... LetThereBeCode 360 — 9y
0
Hm, didn't seem to change anything, but. I hadn't read the binding event part. Mind telling me more about that? Sorry, I'm still learning this stuff. RedemptedNutella 15 — 9y
0
Please post the code that you are using, so I can see what is wrong. LetThereBeCode 360 — 9y
0
http://pastebin.com/8LBesbaJ Local script inside a tool. RedemptedNutella 15 — 9y
0
On line 35 and 36, you are again using the variable instead of the actual value. Define 'SLASH_DAMAGE' and 'SPECIAL_DAMAGE' before the event. Then, in the event, change those too, when changing the BaseDmg. LetThereBeCode 360 — 9y
0
Thanks alot! Got it perfectly working with your help. does this website have any credit system? so i can give you credit for solving the problem. RedemptedNutella 15 — 9y
0
Click 'Accept Answer' next to my answer, on the right side. And upvote my answer if you liked it. LetThereBeCode 360 — 9y
0
There doesn't seem to be an accept answer button. and i need a certain reputation to upvote, RedemptedNutella 15 — 9y
0
I don't know why the accept answer doesn't show though. It makes it easier for people to see what is solved and what is not. LetThereBeCode 360 — 9y
0
Actualy, It would appear that it works in studio testing, But in the actual game, when i tried to test it, it didn't seem to work. RedemptedNutella 15 — 9y
Ad

Answer this question