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

How to make a tools value disable a script?

Asked by 5 years ago

I'm trying to make it so when a guns ammo = 0, it makes the sound script for the gun disabled. Here is what I tried:

1if script.Parent.Ammo.Value <= 0 then
2    script.Parent.Sound.Disabled = true
3end

When I tested it, however, the script didn't disable.

0
Are there any string, bool or number values in the gun? Also on your script, only the sound will get disabled not the whole script.. SilentsReplacement 468 — 5y
0
Uhm y User#17685 0 — 5y
0
Uhmm you need to '.Changed' or 'GetPropertyChangedSignal', else your script only ran once User#17685 0 — 5y
0
is that the whole script? User#17685 0 — 5y

1 answer

Log in to vote
0
Answered by
DrShockz 233 Moderation Voter
5 years ago

Here I wrote a script for you!

1local ammo = script.Parent.Ammo
2 
3ammo.Changed:Connect(function()
4    if ammo.Value <= 0 then
5        script.Parent.Sound.Disabled = true
6    end
7end)

Now the fun part of reading over the code and seeing what it does!

Line 1 - Referencing the ammo Boolean.

1local ammo = script.Parent.Ammo -- Referencing the Boolean

Line 3 - 7 -- Checking if ammo under number then disabling.

1ammo.Changed:Connect(function() ---- Creates a function when ammo value changed.
2    if ammo.Value <= 0 then --- Checks if the value is equal to or under '0'
3        script.Parent.Sound.Disabled = true --- If it is it will disable your "Sound" script.
4    end --- Closes if statement
5end) -- Closes function.

Hope you enjoyed the script! - DrShockz :)

0
ty! hihowareya115 53 — 5y
Ad

Answer this question