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

How to add 25 to a value and then remove 25 from the value, not change the full value? [closed]

Asked by 5 years ago
Edited 5 years ago

Gyazo link

local particleem = workspace:WaitForChild("Igniterone").igniteparts.emiter.ParticleEmitter
local clickdet = script.Parent.ClickDetector
local button = script.Parent
local status = false
local sound = workspace:WaitForChild("Igniterone").igniteparts.Sound
local energyvtext = workspace:WaitForChild("EnergyPanel").Part.SurfaceGui.energyvalue
local energyvalue = tonumber(energyvtext.Text)
print(energyvalue)
local newval
local newvalstring
clickdet.MouseClick:Connect(function()
    if status == false then
        particleem.Enabled = true
        button.BrickColor = BrickColor.new("Really red")
        sound.Playing = true
        newval = (energyvalue + 24)
        newvalstring = tostring(newval)
        print(typeof(newval))
        energyvtext.Text = newvalstring
        status = true

    elseif status == true then
        particleem.Enabled = false
        button.BrickColor = BrickColor.new("Lime green")
        sound.Playing = false
        newval = (energyvalue - 25)
        newvalstring = tostring(newval)
        print(typeof(newval))
        energyvtext.Text = newvalstring
        status = false
    end
end)

Everything here is working except that it changes the value of energyvtext, i want it to add 25 to it and remove 25 but it doesn't, it just changes, not adds or removes.

0
By full im guessing u mean max? The_Pr0fessor 595 — 5y
0
Why is this question upvoted? It's not even a good question. DeceptiveCaster 3761 — 5y

Closed as Not Constructive by Fragmentation123 and DeceptiveCaster

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
Psudar 882 Moderation Voter
5 years ago

Bit of a logic problem you got going here, an easy fix I think. You're setting newval to energyvalue -25. Instead, you should set the newVal to newVal = newVal -25.

If you actually want energy value to change, then you should do something like this:

newVal = energyValue -25; energyValue = newVal

Heres what it looks like in your own script:

clickdet.MouseClick:Connect(function()
    if status == false then
        particleem.Enabled = true
        button.BrickColor = BrickColor.new("Really red")
        sound.Playing = true
        newval = energyvalue + 24
    energyvalue = newval
        newvalstring = tostring(newval)
        energyvtext.Text = newvalstring
        status = true
    elseif status == true then
        particleem.Enabled = false
        button.BrickColor = BrickColor.new("Lime green")
        sound.Playing = false
        newval = energyvalue - 25
    energyvalue = newval
        newvalstring = tostring(newval)
        energyvtext.Text = newvalstring
        status = false
    end
end)
Ad