Need Help With Confusing IntValue System

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to know how I can make it so every .1 seconds, this value adds 1, and if it reaches 100, it will stop giving IntValue. If the player then loses IntValue with 100, I want it to add back 1 every .1 second, but ive done simple stuff and it isn’t working.

  2. What is the issue? I tried multiple stuff to make this system work, but for some reason it won’t work. The code will be below after 3.

  3. What solutions have you tried so far? I tried making a while true do loop and it check’s if the value is not 100, if it is not 100 then it will add, but if the player loses IntValue it won’t give back.

I have a dash script which is a LocalScript and if the player pressed E, that’s where it takes away 25 En. The ServerScript is the script which is adding IntValue. The localscript is in StarterCharacterScripts. and the serverscript is in the IntValue and the IntValue is in startercharacterscript

ServerScript:

local en = script.Parent

local function addEn()
	en.Value += 1
end

while true do
	if en.Value ~= 100 then
		addEn()
	end
	wait(.1)
end

LocalScript:

--|| SERVICES ||--
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local Character = script.Parent
local Torso = Character.HumanoidRootPart
local Humanoid = Character:WaitForChild("Humanoid")
 
local Dash = Humanoid:LoadAnimation(ReplicatedStorage.Animations.Dash)
 
local Properties = {
    Velocity = 25,
    Duration = 0.5,
    Keybind = Enum.KeyCode.E,
    LastDash = tick(),
    Cooldown = 0.01,
}
 
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
    if Input.KeyCode == Properties.Keybind then
       
		if tick() - Properties.LastDash >= Properties.Cooldown then
			if Character.En.Value >= 1 then
				Properties.LastDash = tick()

				Dash:Play()
           --[[ local BodyVelocity = Instance.new("BodyVelocity")
                BodyVelocity.MaxForce = Vector3.new(-.01,-0,0) *  500000
                BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * Properties.Velocity
                BodyVelocity.Parent = Character.HumanoidRootPart--]]
				Torso.Velocity += Torso.CFrame.RightVector*100
				wait(Properties.Duration)
				script.Parent.En.Value -= 25
				--  BodyVelocity:Destroy()
			else
				return false
			end
        end
    end
end)

image

local en = script.Parent

while en.Value <= 100 do
 en.Value +=1 
task.wait(.1)
end

If I lose IntValue, it won’t go back up.

What do you mean??? Are you saying if the IntValue is destroyed, it wont work?

I made it so when the player pressed E, they dash sideways and it takes away 25 Energy (The IntValue) from the value, but the IntValue value won’t go back up.

Wait try this,

local en = script.Parent

while en.Value >= 100 do
 en.Value +=1 
task.wait(.1)
end

Ok, now it’s not giving en. Are you even testing these?

The other one should work anyways

You can’t say this without showing what you did in the script.

I did… What do you mean? I showed it at the top of the page. What are you on about?

Not that script, your e dash script,

--|| SERVICES ||--
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local Character = script.Parent
local Torso = Character.HumanoidRootPart
local Humanoid = Character:WaitForChild("Humanoid")
 
local Dash = Humanoid:LoadAnimation(ReplicatedStorage.Animations.Dash)
 
local Properties = {
    Velocity = 25,
    Duration = 0.5,
    Keybind = Enum.KeyCode.E,
    LastDash = tick(),
    Cooldown = 0.01,
}
 
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
    if Input.KeyCode == Properties.Keybind then
       
		if tick() - Properties.LastDash >= Properties.Cooldown then
			if Character.En.Value >= 1 then
				Properties.LastDash = tick()

				Dash:Play()
           --[[ local BodyVelocity = Instance.new("BodyVelocity")
            BodyVelocity.MaxForce = Vector3.new(-.01,-0,0) *  500000
            BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * Properties.Velocity
            BodyVelocity.Parent = Character.HumanoidRootPart--]]
				Torso.Velocity += Torso.CFrame.RightVector*100
				Character.En.Value -= 30
				wait(Properties.Duration)
				--  BodyVelocity:Destroy()
			else
				return false
			end
        end
    end
end)

I think i know what you mean. When the IntValue is 100, the while loop won’t play?

If the player pressed E, it takes away 25 en, but it won’t add back en after that. I also need it so if the player reaches 100 en, it stops giving en, but after they press E they will lose 25 en and it should go back up after that again.

You just said what i said basically, Lemme fix this.

local en = script.Parent.Value

while true do
   if en.Value <= 100 then
	en.Value +=1 
	print(en.Value)
   end
   task.wait(.1)
end

i don’t think you should use “script.Parent.Value” as the Vairiable since it just gets the first value of it. It will be a number that goes up, but it won’t change the Value of en. I’ll try it anyway

I made it to make it easier for me, you can change the variable.

doesn’t work. 30 lettersssssssss

Hm? It’s working for me though. Change the variable to what you want it to be,

the dash script is a local script, in StarterCharacterScripts and the En intvalue is also in StarterCharacterScripts.

Wait… I think I know why its not working… Localscript… 1 sec

I have a dash script which is a LocalScript and if the player pressed E, that’s where it takes away 25 En. The ServerScript is the script which is adding IntValue. The localscript is in StarterCharacterScripts. and the serverscript is in the IntValue and the IntValue is in startercharacterscript
image