Dying causes the afterframes to no longer appear on the player alongside not letting them dash at all

Heya there.

Working on a dash feature on a game. The issue is that if you die, the afterframes will not appear on you, only appearing where you last die and won’t let you dash at all.

Script

--[[SERVICES]]--
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

--[[FUNCTIONALITY]]--
--//Getting the player
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character.Archivable = true
local DashAttachment = Instance.new("Attachment",Character.PrimaryPart)

--//Change Iframes
local function TurnOnIFrames(Boolen)
	if Boolen == true then
		for _, Bodypart in pairs(Character:GetChildren()) do
			if Bodypart:IsA("BasePart") then
				Bodypart.CanTouch = false
				Bodypart.CanQuery = false
			end
		end
	else
		for _, Bodypart in pairs(Character:GetChildren()) do
			if Bodypart:IsA("BasePart") then
				Bodypart.CanTouch = true
				Bodypart.CanQuery = true
			end
		end
	end
end

--//Dashing
local DashCD = false

local function DashUser(actionName, inputState)
	if actionName == "Dash" and inputState == Enum.UserInputState.Begin then
		if DashCD then return end
		DashCD = true
		
		--//Dash
		local LinearVelocity = Instance.new("LinearVelocity",Character.PrimaryPart)
		LinearVelocity.MaxForce = math.huge
		LinearVelocity.VectorVelocity = Character.PrimaryPart.CFrame.LookVector * 100
		LinearVelocity.Attachment0 = DashAttachment
		
		--//Giving player iframes
		TurnOnIFrames(true)
		
		--//Frames
		local FancyFrames = coroutine.create(function()
			while task.wait(0) do
				
				local FrameChar = Character:Clone()
				FrameChar.Parent = game.Workspace.Debris
				FrameChar.Name = "Afterframe"
				FrameChar.Head.face:Destroy()

				for _, Bodypart in pairs(FrameChar:GetChildren()) do
					if Bodypart:IsA("Part") and Bodypart.Name ~= "HumanoidRootPart" then
						
						local FrameBodyPart = Bodypart:Clone()
						FrameBodyPart.Parent = FrameChar
						FrameBodyPart.Anchored = true
						FrameBodyPart.Transparency = 0.5
						FrameBodyPart.BrickColor = BrickColor.new("White")
						FrameBodyPart.CanTouch = false
						FrameBodyPart.CanQuery = false
						FrameBodyPart.CollisionGroup = "DashFrames"
						---FrameBodyPart.CFrame = Bodypart.CFrame + FrameBodyPart.CFrame.LookVector * -2

						for _, Weld in pairs(FrameBodyPart:GetChildren()) do
							if Weld:IsA("Weld") or Weld:IsA("Motor6D") then
								Weld:Destroy()
							end
						end

						game:GetService("Debris"):AddItem(FrameChar,0.5)
						game:GetService("Debris"):AddItem(FrameBodyPart,0.5)
						Bodypart:Destroy()
					end
				end
				
			end
		end)
		coroutine.resume(FancyFrames)

		game:GetService("Debris"):AddItem(LinearVelocity,0.05)
		
		task.wait(0.3)
		TurnOnIFrames(false)
		coroutine.close(FancyFrames)
		task.wait(1)
		DashCD = false
	end
end

ContextActionService:BindAction("Dash",DashUser,false,Enum.KeyCode.LeftShift)

If the script isn’t a StarterCharacterScripts LocalScript, you should try this instead of local Character = Player.Character or Player.CharacterAdded:Wait():

local function CharacterAdded(Character: Model)
	-- Handle dashing here
end
CharacterAdded(Player.Character or Player.CharacterAdded:Wait()))
Player.CharacterAdded:Connect(CharacterAdded)

The reason it’s not working is because you’re only setting the Character variable once, it’ll only run on the first time you spawn, and once your character gets respawned it won’t run again because the character was deleted.

Also, FYI, there’s a Attachment named “RootAttachment” in the HumanoidRootPart with the position set to 0,0,0. You don’t need to create a new attachment, but that’s up to you.

Alright I’ll try it later, thanks you!