Stamina/Combat System Help Needed

I need to have punches become slower when you have less stamina/speed and also I need the stamina to regen properly. The stamina regen works partly, if the value starts off before the topstam value then it regens as it should. On the 2nd script (fighting script) the keybind to animation works fine but the adjust speed dosen’t seem to be working, I tested it out with 0 adjusted speed and it played normally as if the adjust speed was set to 1. Also for some weird reason when I play the animation and lose 1 stamina value (which is what i set it to) I can’t go past 11 stamina until it stops completely. And the part of the script where I try to lower the maximum stam won’t you’re stamina gets low enough dosen’t seem to work either. I’ve been working on this for a decent chunk of time and used the devwiki alot but I don’t know if I just don’t get it but it dosen’t seem to be working as I intended

Stamina Handler

local Stamina = game.Players.LocalPlayer.Character.IntValues.Stamina
local DefStamina = game.Players.LocalPlayer.Character.IntValues.DefStam


if Stamina.Value <DefStamina.Value then
	repeat
		Stamina.Value = Stamina.Value + 1
			wait(2)
	until
		Stamina.Value == DefStamina.Value
end

if Stamina.Value == DefStamina.Value - 5 then
	print ("MaxStam Dropped")
	DefStamina.Value = DefStamina.Value - 1
end

		
script.Parent.IntValues.Stamina.Changed:Connect(function(Stam)
	Stamina.Value = Stam
end)

script.Parent.IntValues.DefStam.Changed:Connect(function(TopStamina)
	DefStamina.Value = TopStamina
end)

FightingHandler

wait(0.2)
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game.ReplicatedStorage
local Players = game:GetService("Players")
local player = script.Parent
local P1 = script.Parent.KeyBinds.P1.Value
local P2 = script.Parent.KeyBinds.P2.Value
local P3 = script.Parent.KeyBinds.P3.Value
local P4 = script.Parent.KeyBinds.P4.Value
local P5 = script.Parent.KeyBinds.P5.Value
local P6 = script.Parent.KeyBinds.P6.Value
local Power = script.Parent.IntValues.Power
local Speed = script.Parent.IntValues.Speed
local Stamina = script.Parent.IntValues.Stamina
local Hand = script.Parent.IntValues.Hand
local DamageDebounce = false
local TopStam = script.Parent.IntValues.DefStam

--Hit
script.Parent:WaitForChild(Hand.Value).Touched:Connect(function(hit)
	if DamageDebounce == false then
		DamageDebounce = true
			local hitplayer = hit.Parent
			if hit.Parent.Humanoid and hit.Parent.Humanoid ~= script.Parent.Humanoid and hit.Parent.Humanoid.Health >0 then
			game.ReplicatedStorage.FightingEvents.Landed:FireServer(hitplayer, Hand.Value, Power)
			wait(0.5)
			DamageDebounce = false
		end
	end
end)

print("Client Ready")

--FightingBinds, P1
UserInputService.InputBegan:Connect(function(input, event)
	if input.KeyCode == Enum.KeyCode.E then
		print("E Pressed")
	local PunchPower = Power.Value - 17
	local Animation = script.Parent.Animations.P1
	local Punch = player:FindFirstChild("Humanoid"):LoadAnimation(Animation)
		
	local PunchSpeed = Speed.Value + Stamina.Value
		
	
	if PunchSpeed <40 and PunchSpeed >31 then
			Punch:AdjustSpeed(2)
			Punch:Play()
			Stamina.Value = Stamina.Value - 1
	end
	
	if PunchSpeed <31 and PunchSpeed >21 then
			Punch:AdjustSpeed(1)
			Punch:Play()
			Stamina.Value = Stamina.Value - 1
	end
	
	if PunchSpeed <21 and PunchSpeed >0 then
			Punch:AdjustSpeed(1)
			Punch:Play()
			Stamina.Value = Stamina.Value - 1
	end
		
	
		
	end
end)

Both are local scripts inside of the player, No Errors either.

If theres extra details needed just let me know

What does your output show? I know that you said that there weren’t errors but is there anything else in the output like the things you printed? Also, try adding print("This happened") Although obviously the “This happened” would be whatever you need to know where it is around your code in different areas. If one part prints and the other doesn’t you’ll know what your issues are. This is very useful for debugging.

1 Like

Hi. I fixed some of the issues but some still stand, I’ll list what I was able to fix.

-The Stamina Not Regening Properly

I’m still facing the issues of the animation speeds and the stamina not going past 11

Stamina Handler

local Stamina = game.Players.LocalPlayer.Character.IntValues.Stamina
local DefStamina = game.Players.LocalPlayer.Character.IntValues.DefStam
local Punching = script.Parent.FightingValues.Punching

while true do
	wait(1)
if Stamina.Value <DefStamina.Value and Punching.Value == false then
	print("Regening")
	repeat
		Stamina.Value = Stamina.Value + 1
			wait(2)
	until
		Stamina.Value == DefStamina.Value
	end
end

		
script.Parent.IntValues.Stamina.Changed:Connect(function(Stam)
	Stamina.Value = Stam
end)

script.Parent.IntValues.DefStam.Changed:Connect(function(TopStamina)
	DefStamina.Value = TopStamina
end)

And no theres no issues with printing, everything I put to print printed.

1 Like