Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a tools value disable a script?

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.

4 comments

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

0

Uhm y

0

Uhmm you need to '.Changed' or 'GetPropertyChangedSignal', else your script only ran once

0

is that the whole script?

1 answer

✓ Accepted answer

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

1 comment

0

ty!

This discussion is preserved as it was. New answers, comments, and votes are closed.