Why is it overlapping?

Sprint System (its changing the animation):


-- Services --
local CAS = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local TweenServiceInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local SoundTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

-- Script Infos -- 
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local cam = game.Workspace.Camera
local SFX = script["running man loop"]

local HearthBreakTween
local SoundTween

-- Settings -- 

local sprinting = false
local StaminaUsage = 0.02
local ReGainingStamina = 0.2
local lastSprint = 0
local reChargeTime = 4
local OverLoaded = false
local HeavyBreathing = false

-- Animation --
local Sprint = character.Animate.run.RunAnim
local SprintAnim = humanoid.Animator:LoadAnimation(Sprint)

cam.FieldOfView = 60

local StaminaEating = RunService.RenderStepped:Connect(function(delta)
	
	local Stamina = humanoid:GetAttribute("Stamina")
	local Sprintable = humanoid:GetAttribute("Sprintable")
	
	if not Stamina and not Sprintable then return end 
	
	task.spawn(function()
		if Stamina < 60 and sprinting then
			
			if not cam:FindFirstChild("StaminaColorCorrection") then
				local ColorCorrection = Instance.new("ColorCorrectionEffect", cam)
				ColorCorrection.Name = "StaminaColorCorrection"
			end
			
			local ColorCorrection = cam.StaminaColorCorrection
			
			if HearthBreakTween then
				HearthBreakTween:Cancel()
			end
			
			if SoundTween then
				SoundTween:Cancel()
			end

			HearthBreakTween = TweenService:Create(ColorCorrection, TweenServiceInfo, {
				Contrast = 1, 
				TintColor = Color3.fromRGB(159, 62, 255)
			})
			
			SoundTween = TweenService:Create(SFX, SoundTweenInfo, {
				Volume = 3
			})
			
			HearthBreakTween:Play()
			SoundTween:Play()
			
			HeavyBreathing = true
			
		elseif Stamina > 30 and HeavyBreathing then
			
			if not cam:FindFirstChild("StaminaColorCorrection") then
				local ColorCorrection = Instance.new("ColorCorrectionEffect", cam)
				ColorCorrection.Name = "StaminaColorCorrection"
			end

			local ColorCorrection = cam.StaminaColorCorrection
			local oldColorCorrectionContrast = 0
			local oldColorCorrectionTintColor = Color3.fromRGB(255, 255, 255)
	
			if HearthBreakTween then
				HearthBreakTween:Cancel()
			end
			
			if SoundTween then
				SoundTween:Cancel()
			end

			HearthBreakTween = TweenService:Create(ColorCorrection, TweenServiceInfo, {
				Contrast = oldColorCorrectionContrast,
				TintColor = oldColorCorrectionTintColor
			})
			
			SoundTween = TweenService:Create(SFX, SoundTweenInfo, {
				Volume = 0
			})
			
			SoundTween:Play()
			HearthBreakTween:Play()
			
			HeavyBreathing = false
			
		end
	end)
	
	if Stamina < StaminaUsage and Sprintable then
		sprinting = false
		humanoid.WalkSpeed = humanoid:GetAttribute("NormalWalkSpeed")
		SprintAnim:Stop()
		TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()
		OverLoaded = true
	end
	
	if sprinting and Stamina > 0 and humanoid.MoveDirection.Magnitude > 0 and humanoid.WalkSpeed > 0 then
		humanoid:SetAttribute("Stamina", Stamina - StaminaUsage)
		lastSprint = tick()
	else
		if tick() - lastSprint > reChargeTime and Stamina < humanoid:GetAttribute("MaxStamina") then
			humanoid:SetAttribute("Stamina", Stamina + ReGainingStamina)
			OverLoaded = false
		end
	end
	
end)

local function sprint(actionName, inputState, inputType)
	
	local Sprintable = humanoid:GetAttribute("Sprintable")
	local Stamina = humanoid:GetAttribute("Stamina")
	
	if not Sprintable then 
		
		character.HumanoidRootPart.Running.PlaybackSpeed = 0.7
		TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()
		SprintAnim:Stop()
		
		return
		
	end

	if humanoid.WalkSpeed <= 0 then return end

	if inputState == Enum.UserInputState.Begin and humanoid.MoveDirection.Magnitude > 0 and Sprintable then
		sprinting = true
	elseif inputState == Enum.UserInputState.End then
		sprinting = false
	end

	if sprinting and Stamina > StaminaUsage and Sprintable then
		TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 65}):Play()

		humanoid.WalkSpeed = humanoid:GetAttribute("SprintingWalkSpeed")
		SprintAnim:Play()
	elseif Sprintable then
		TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()

		humanoid.WalkSpeed = humanoid:GetAttribute("NormalWalkSpeed")
		SprintAnim:Stop()
	end

end

-- CAS's Bind's -- 
CAS:BindAction("Sprint", sprint, true, Enum.KeyCode.LeftShift)

Now I used UserInputService for the inputs maybe try using UIS for general inputs because bind action is mostly used for cars or tools but UIS is for general inputs

Any input with UIS is also holdable so maybe CAS is for one time presses and UIS is for holding down keys (not sure)

Try to read the documentation it could help

It has nothing to do with CAS, the same thing happens with UIS.

Maybe this has something to do with your run animations speed because when I was programming mine my walk animation was to fast so the sound kept being spam played. Try to create a new animation with the playback speed set to 0.5 or 0.25 and check for results

Iā€™m sorry but this is the least I can do now Iā€™m out of ideas why this could happen

I hope it has finally worked, but if it hasnā€™t then I must apologise for I donā€™t know what to do anymore

The problem has nothing to do with animation or sprint or CAS or UIS or Raycast, I have been trying to explain this from the beginning. The problem is in the GetMarkedReached signal, I told you to look at the console from the beginning, I guess you insistently do not look. When I press each sprint in the console, it prints as if it is playing run many times and when I press each sprint, this print number increases 1 time.

Oh, I apologise I didnā€™t understand that you were trying to me this . Well Iā€™m really not sure anymore Iā€™ll try to see tomorrow.

1 Like

I also found out from your print statements that your Turkish. Salam Aleikum and until tomorrow :slight_smile:

1 Like

I have returned real quick and after reviewing the videos you sent me Iā€™ve realized that sometimes whenever you trigger the input it prints twice or even three times. Iā€™ve seen posts that some Users have been pressing keys on their keyboards and the input either doesnā€™t register or it registers multiple times. But just to make sure does this ā€œprinting many timesā€ happen when you register an input once?

Edit: Canā€™t reply anymore (Expect new messages by tomorrow)

1 Like

Yes, the number of prints increases when I press once

This could be a technical issue within your keyboard or input device although I donā€™t know which posts referred to this issue I will send you anything important by tomorrow ASAP inshallah

1 Like

Maybe someone else can help, huh?

I will send you a copy of the game to make it more understandable

Alright thank you. Iā€™ll try to figure it out
Do you give me consent to check out the necessary code that might be causing the issue?

there you will be able to see all the scripts (only relevant scripts)

1 Like

Here it is!
testingbug2.rbxl (62.9 KB)

if character spawns with r15, reset character

Alright understood will take care

you have to publish the game and make the character model only r6, sorry I just realized it.

1 Like