So I'm trying to make a script that subtracts from an intValue whenever my player is running. For some reason, it just doesn't do anything with an if statement that I put there. I don't really know how to explain, but any help is appreciated.

Server:

local remoteEvent = game.ReplicatedStorage:WaitForChild("Stats-Related"):WaitForChild("Health/Stamina")
local staminaRemover = game.ReplicatedStorage:WaitForChild("Stats-Related"):WaitForChild("StaminaRemover")
local runningValue = game.ReplicatedStorage:WaitForChild("Stats-Related"):WaitForChild("RunningValue")

remoteEvent.OnServerEvent:connect(function(player, stat)
	local char = game.Workspace:WaitForChild(player.Name)
	local running = char:WaitForChild("StatsStuffs").Running
	local limitBreaker = char:WaitForChild("Skills"):WaitForChild("LocalLimitBreaker"):WaitForChild("LimitBreaker")
	
	-- Stamina:
	if stat == "stamina" then
		local stamStuff = player:WaitForChild("StaminaStuff")
		local stam = stamStuff:WaitForChild("Stamina")
		local maxStam = stamStuff:WaitForChild("MaxStamina")
		if player.Name == "Knineteen19" then
			maxStam.Value = (player.leaderstats.Level.Value*5+95)*5
		else
			maxStam.Value = player.leaderstats.Level.Value*5+95
		end
		if limitBreaker.Value == false and running.Value == false then
			if stam.Value <= maxStam.Value*0.95 then
				stam.Value = stam.Value + maxStam.Value*0.05
			elseif stam.Value >= maxStam.Value*0.95 then
				stam.Value = maxStam.Value
			end
		end
		
	-- Health:
	elseif stat == "health" then
		local healthstat = player:WaitForChild("Health")
		local maxstat = player:WaitForChild("MaxHealth")
		local level = player:WaitForChild("leaderstats"):WaitForChild("Level")
		if player.Name == "Knineteen19" then
			char:WaitForChild("Humanoid").MaxHealth = (level.Value * 5 + 95)*5
			healthstat.Value = char.Humanoid.Health/5
			maxstat.Value = char.Humanoid.MaxHealth/5
		else
			char:WaitForChild("Humanoid").MaxHealth = level.Value * 5 + 95
			healthstat.Value = char.Humanoid.Health
			maxstat.Value = char.Humanoid.MaxHealth
		end
	end
end)
	
staminaRemover.OnServerEvent:connect(function(player,number)
	local stamina = player:WaitForChild("StaminaStuff"):WaitForChild("Stamina")
	
	stamina.Value = stamina.Value - number
end)

runningValue.OnServerEvent:connect(function(player,enabled)
	local running = game.Workspace:WaitForChild(player.Name):WaitForChild("StatsStuffs"):WaitForChild("Running")
	if enabled == false then
		running.Value = true
	elseif enabled == true then
		running.Value = false
	end
end)

Client:

local player = game.Players.LocalPlayer
local char = player.Character
local stats = player:WaitForChild("Stats")
local leaderstats = player:WaitForChild("leaderstats")
local mouse = player:GetMouse()
local inmotion = false
local multiplier = char.Humanoid:WaitForChild("XP Multiplier")
local running = script:WaitForChild("Running")
local damage = false
local db = false

local remoteEvent = game.ReplicatedStorage:WaitForChild("Stats-Related").UpStats
local punchingRemoteEvent = game.ReplicatedStorage:WaitForChild("Skills"):WaitForChild("Punching")
local limitBreakerEvent = game.ReplicatedStorage:WaitForChild("Skills"):WaitForChild("LimitBreaker")
local staminaRemover = game.ReplicatedStorage:WaitForChild("Stats-Related"):WaitForChild("StaminaRemover")
local runningValue = game.ReplicatedStorage:WaitForChild("Stats-Related"):WaitForChild("RunningValue")

local strength = stats:WaitForChild("Strength")
local strengthlvl = strength:WaitForChild("StrengthLevel")
local sxp = strength:WaitForChild("StrengthXp")
local smax = strength:WaitForChild("StrengthMaxXp")
local pushwaittime = 3

local agility = stats:WaitForChild("Agility")
local agillvl = agility:WaitForChild("AgilityLevel")
local axp = agility:WaitForChild("AgilXp")
local amax = agility:WaitForChild("AgilMaxXp")
local lungewaittime = 2.2

local jump = stats:WaitForChild("Jump")
local jumplvl = jump:WaitForChild("JumpLevel")
local jxp = jump:WaitForChild("JumpXp")
local jmax = jump:WaitForChild("JumpMaxXp")
local squatwaittime = 1.8

local stamStuff = player:WaitForChild("StaminaStuff")
local stamina = stamStuff:WaitForChild("Stamina")
local maxStam = stamStuff:WaitForChild("MaxStamina")

local squatanim = "rbxassetid://2219181231"
local lungeanim = "rbxassetid://2380575156"
local pushanim = "rbxassetid://2219303213"
local punch1 = "rbxassetid://2219184536"
local punch2 = "rbxassetid://2219185342"
local punch3 = "rbxassetid://2219186257"
local punch4 = "rbxassetid://2219189003"
local runAnimId = "rbxassetid://2394625968" 

local punch1wait = 0.3
local punch2wait = 0.3
local punch3wait = 0.3
local punch4wait = 0.4

-- Squat
mouse.KeyDown:connect(function(key)
	if key == "c" then
		if inmotion == false and db == false then
			inmotion = true
			db = true
			local anim = Instance.new("Animation")
			anim.AnimationId = squatanim
			local squat = char.Humanoid:LoadAnimation(anim)
			squat.Priority = Enum.AnimationPriority.Action
			squat:Play()
			wait(squatwaittime)
			remoteEvent:FireServer("jump")
			squat:Stop()
			inmotion = false
			db = false
		end
	end
end)

-- Lunge
mouse.KeyDown:connect(function(key)
	if key == "x" then
		if inmotion == false and db == false then
			inmotion = true
			db = true
			local anim = Instance.new("Animation")
			anim.AnimationId = lungeanim
			local lunge = char.Humanoid:LoadAnimation(anim)
			lunge.Priority = Enum.AnimationPriority.Action
			lunge:Play()
			wait(lungewaittime)
			remoteEvent:FireServer("agility")
			lunge:stop()
			inmotion = false
			db = false
		end
	end
end)

-- Pushup
mouse.KeyDown:connect(function(key)
	if key == "z" then
		if inmotion == false and db == false then
			inmotion = true
			db = true
			local anim = Instance.new("Animation")
			anim.AnimationId = pushanim
			local pushanim = char.Humanoid:LoadAnimation(anim)
			pushanim.Priority = Enum.AnimationPriority.Action
			pushanim:Play()
			wait(pushwaittime)
			pushanim:Stop()
			remoteEvent:FireServer("strength")
			inmotion = false
			db = false
		end
	end
end)

-- Sprint
mouse.KeyDown:connect(function(key)
	if key:byte() == 50 then
		if running.Value == false then
			if inmotion == false and stamina.Value >= 0 then
				local limitBreaker = char:WaitForChild("Skills"):WaitForChild("LocalLimitBreaker"):WaitForChild("LimitBreaker")
				local anim = Instance.new("Animation")
				
				anim.AnimationId = runAnimId
				runAnim = char.Humanoid:LoadAnimation(anim)
				runAnim.Priority = Enum.AnimationPriority.Action
				inmotion = true
				runningValue:FireServer(false)
				runAnim:Play()
				runAnim:AdjustSpeed((agillvl.Value*0.004+1.1))
				char.Humanoid.WalkSpeed = agillvl.Value * 0.3 + 25
				char.Humanoid.JumpPower = jumplvl.Value * 0.5 + 60
				while running.Value == true and wait(0.1) do
					if stamina.Value > 0 then -- This is where it just ignored the if statement and moves on.
						staminaRemover:FireServer(1)
					elseif stamina.Value <= 0 then
						inmotion = false
						runningValue:FireServer(true)
						runAnim:Stop()
						char.Humanoid.WalkSpeed = 16
						char.Humanoid.JumpPower = 50
						break
					end
					if limitBreaker.Value == true then
						if stamina.Value > 0 then -- Of course, it does the same thing here.
							staminaRemover:FireServer(5)
						elseif stamina.Value <= 0 then
							limitBreakerEvent:FireServer(true)
							break
						end
					end
				end
			end
		elseif running.Value == true then
			inmotion = false
			runningValue:FireServer(true)
			runAnim:Stop()
			char.Humanoid.WalkSpeed = 16
			char.Humanoid.JumpPower = 50
		end
	end
end)

-- Punching
local punching = false
local count = 0
mouse.KeyDown:connect(function(key)
	if key == "e" and damage == false then
			local anim = Instance.new("Animation")
			if db == false and damage == false then
				if count == 0 then
					db = true
					anim.AnimationId = punch1
					local punchanim = char.Humanoid:LoadAnimation(anim)
					punchanim.Priority = Enum.AnimationPriority.Action
					punchanim:Play()
					punchingRemoteEvent:FireServer("LeftHand",punching,1)
					damage = true
					wait(punch1wait)
					damage = false
					punchanim:Stop()
					count = 1
					db = false
					punching = false
				elseif count == 1 then
					db = true
					anim.AnimationId = punch2
					local punchanim = char.Humanoid:LoadAnimation(anim)
					punchanim.Priority = Enum.AnimationPriority.Action
					punchanim:Play()
					punchingRemoteEvent:FireServer("RightHand",punching,2)
					damage = true
					wait(punch2wait)
					damage = false
					punchanim:Stop()
					count = 2
					db = false
					punching = false
				elseif count == 2 then
					db = true
					anim.AnimationId = punch3
					local punchanim = char.Humanoid:LoadAnimation(anim)
					punchanim.Priority = Enum.AnimationPriority.Action
					punchanim:Play()
					punchingRemoteEvent:FireServer("LeftFoot",punching,3)
					damage = true
					wait(punch3wait)
					damage = false
					punchanim:Stop()
					count = 3
					db = false
					punching = false
				elseif count == 3 then
					db = true
					anim.AnimationId = punch4
					local punchanim = char.Humanoid:LoadAnimation(anim)
					punchanim.Priority = Enum.AnimationPriority.Action
					punchanim:Play()
					punchingRemoteEvent:FireServer("RightFoot",punching,4)
					damage = true
					wait(punch4wait)
					damage = false
					punchanim:Stop()
					count = 0
					db = false
					punching = false
				end
			end
			punching = false
	end
end)

6 comments

1

Try using a print() each time to see if each function is working correctly or not

0

I already did, that's how I know where the problem is. It just skips over lines 132-141 entirely without showing errors.

0

that probably means stamina.Value isn't greater than 0

0

have it print stamina.Value?

0

It's not less that or equal to 0 either. And I tried that, it printed nothing, no matter where I put the print

0

Thanks for trying though!