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

This line of code won't let me subtract an Int Value..?

I made a simple piece of code for an ammo system that I was making. This is the script that I made:

script.Parent.ammo.Value = script.Parent.ammo.Value - 1

For some reason, it won't subtract the value and I'm 1000% certain that I did type the code correctly. Is this some ROBLOX bug? Because no error outputs are showing up either.

3 comments

0

Did you try adding a line after the code for print(script.Parent.ammo.Value)

0

Make sure your script isn't disabled

0

OMG IM DUMB LOL! The gui text didn't go down each click because I did script.Parent.Gui.Ammo instead of script.Parent.Gui.Ammo.Text, in simpler words, I just forgot .Text, smhhhh lol..

1 answer

When code doesn't seem to be running, there are a few things to check:

  • Is it a LocalScript in a place that only a Script will run or vice versa? Check https://developer.roblox.com/en-us/api-reference/class/LocalScript and https://developer.roblox.com/en-us/api-reference/class/Script
  • Is it a LocalScript and you're inspecting the server side value? Due to FilteringEnabled, local script can't change values for the server directly - use RemoteEvents instead
  • As greatneil80 says, double check your script isn't Disabled
  • To confirm that the code is running at all, put a print statement before your code (to confirm that it has a chance to run) and after it as well (to confirm that it ran without errors, despite not showing them in the output -- this can occur if you use coroutine.resume(coroutine.create(function() --[[your code here]] end)) if you haven't had the coroutine wait or otherwise yield yet
  • If the code is running, make sure you're inspecting the same thing your script is modifying. print(script.Parent.ammo:GetFullName()) might help, for instance. Printing its value before/after will confirm that the script is having the desired effect - perhaps a different script is undoing your efforts instead of this one not working.

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