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

How would I subtract from a text label?

What I mean is. I have a weapon and I also have a GUI and the text is set at 25. When I fire the weapon I want it to subtract from the text label. I don't know how to do this. What would I write in the code. My guess was something like this.

fire = true game.StarterGui.ScreenGui.Frame.Label.Text = -1

I don't know something along those lines. I just need some help.

1 answer

If you looking to subtract from a string value you need to use tonumber

For example if you wanted your TextLabel's text to have 5 taken away each time the player clicks a button then it would go like this:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.TextLabel.Text = tonumber(script.Parent.Parent.TextLabel.Text) - 5
end

And just for good measure, DON'T ACCESS GUIS THROUGH STARTERGUI. You need to Access it from the PlayerGui so use script.Parent to find what you are looking for.

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