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

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

Asked by 4 years ago
Edited 4 years ago

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.

0
Did you try adding a line after the code for print(script.Parent.ammo.Value) Jexpler 63 — 4y
0
Make sure your script isn't disabled greatneil80 2647 — 4y
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.. iinaoriku 52 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Answer this question