Tool with stamina Breaks once stamina Finishes

So i have a weapon if you click with it, it takes the players stamina when the stamina is finished you wont be able to use the tool , but once your stamina finishes and then regens the tool stops working

local tool = script.Parent
local character
local equipAnim
local debounce = false

local tweenService = game:GetService("TweenService")
local tInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local t = tweenService:Create(script.Parent.Light, tInfo, {Color = Color3.fromRGB(248, 248, 248)})
local t2 = tweenService:Create(script.Parent.Light, tInfo, {Color = Color3.fromRGB(0, 0, 0)})

tool.Equipped:Connect(function()
	if workspace.BloodHour.Value then
		t2:Play()
		tool.Light.SpotLight.Enabled = false
	else
		t:Play()
		tool.Light.SpotLight.Enabled = true
	end
	character = tool.Parent
	equipAnim = character.Humanoid:LoadAnimation(tool.Idle)
	equipAnim:Play()
end)

tool.Unequipped:Connect(function()
	equipAnim:Stop()
end)

tool.Activated:Connect(function()
	if not debounce and character.stamina.Value >= 12.5 and not workspace.BloodHour.Value then
		debounce = true
		local swingAnim = character.Humanoid:LoadAnimation(tool.Swing)
		swingAnim:Play()
		local hitA = false
		
		tool.Handle.Slash:Play()
		local chance = math.random(1, 3)
		local connection = tool.Handle.DamageBox.Touched:Connect(function(hit)
			if hit.Name ~= "ObservationHitbox"then
				if not hitA then
					hitA = true
					tool.Handle.Deflect.PlaybackSpeed = (1 + tonumber("0."..math.random(3, 6)))
					tool.Handle.Deflect:Play()
					if workspace:FindFirstChild("Rake") then
						local headshot = 1
						if hit:IsDescendantOf(workspace.Rake.Head) then
							workspace.Rake.Headshot.Value = true
							headshot = 2
						end
						if hit:IsDescendantOf(workspace.Rake) then
							if workspace.Rake.Ragdoll.Value then
								workspace.Rake.RagdollTime.Value += 1.5
							else
								if chance == 1 then
									workspace.Rake.RagdollTime.Value += 0.75
								else
									workspace.Rake.RagdollTime.Value += 1.5
								end
							end
							workspace.Rake.Monster:TakeDamage(math.random(4, 6) * headshot)
						end
					end
				end
			end
		end)
		wait(0.65)
		connection:Disconnect()
		wait(0.4)
		debounce = false
	end
end)

workspace.BloodHour.Changed:Connect(function()
	if workspace.BloodHour.Value then
		t2:Play()
		tool.Light.SpotLight.Enabled = false
	else
		t:Play()
		tool.Light.SpotLight.Enabled = true
	end
end)
1 Like

so once the player runs out of stamina the tool Destroy()s itself? im gonna take a guess and say that this weapon is a stun stick
couldn’t just detect when the stamina Value goes to 0 using an if statement? for example:

if stamina.Value <= 1 then --you could just put 0
tool:Destory()
end

Noo the tool breaks as stops working

I believe he’s wanting the Tool to work again when the Stamina goes back up?

Reference:

I suppose we can just break it down to these lines:

tool.Activated:Connect(function()
	if not debounce and character.stamina.Value >= 12.5 and not workspace.BloodHour.Value then
		debounce = true
		local swingAnim = character.Humanoid:LoadAnimation(tool.Swing)
		swingAnim:Play()
		local hitA = false
		
		tool.Handle.Slash:Play()
		local chance = math.random(1, 3)
		local connection = tool.Handle.DamageBox.Touched:Connect(function(hit)
			if hit.Name ~= "ObservationHitbox"then
				if not hitA then
					hitA = true
					tool.Handle.Deflect.PlaybackSpeed = (1 + tonumber("0."..math.random(3, 6)))
					tool.Handle.Deflect:Play()
					if workspace:FindFirstChild("Rake") then
						local headshot = 1
						if hit:IsDescendantOf(workspace.Rake.Head) then
							workspace.Rake.Headshot.Value = true
							headshot = 2
						end
						if hit:IsDescendantOf(workspace.Rake) then
							if workspace.Rake.Ragdoll.Value then
								workspace.Rake.RagdollTime.Value += 1.5
							else
								if chance == 1 then
									workspace.Rake.RagdollTime.Value += 0.75
								else
									workspace.Rake.RagdollTime.Value += 1.5
								end
							end
							workspace.Rake.Monster:TakeDamage(math.random(4, 6) * headshot)
						end
					end
				end
			end
		end)
		wait(0.65)
		connection:Disconnect()
		wait(0.4)
		debounce = false
	end
end)

Can you implement a couple of else & print statements so that we know what works and what doesn’t?

1 Like

well if you want the tool to work once stamina begins regening or stamina is above a certain number:

if Stamina.Value <= 1 then --you could just put 0
tool.Enabled = false
elseif Stamina.Value >= 10 then --or you could use else for when stamina is above 0
tool.Enabled = true
end