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 4 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:

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

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 — 4y
0
Uhm y User#17685 0 — 4y
0
Uhmm you need to '.Changed' or 'GetPropertyChangedSignal', else your script only ran once User#17685 0 — 4y
0
is that the whole script? User#17685 0 — 4y

1 answer

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

Here I wrote a script for you!

local ammo = script.Parent.Ammo

ammo.Changed:Connect(function()
    if ammo.Value <= 0 then
        script.Parent.Sound.Disabled = true
    end
end)

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

Line 1 - Referencing the ammo Boolean.

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

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

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

Hope you enjoyed the script! - DrShockz :)

0
ty! hihowareya115 53 — 4y
Ad

Answer this question