Why don't it work when i die?

i have a script that spawns a part when I press e, but i become gliched when I reset then press e
here’s my script:

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E then
		local projectile = pathToThePart
		projectile.Parent = workspace
		projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
		projectile.BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
		end
end)

Is this in a localscript or a script?

it is in local script(30 word thingy)

is it in a player character script?

yes it is, there is a mesh in replaced storage named part idk if meshes matter

So the script is in replaced storage?

its in starterplayer scripts…(thirty stuff)

you need to clone the part as it get used up on your first try

Try this

local m = game.Players.LocalPlayer:GetMouse()
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part

m.KeyDown:connect(function(k)
    if(k:lower() == 'e') then
        local projectile = pathToThePart
		projectile.Parent = workspace
		projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
		projectile.BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
    end
end)

there is a error Players.foxnoobkite.PlayerScripts.LocalScript:8: attempt to index nil with ‘KeyDown’

(btw ima go afk so yeah)

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part:clone()

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E then
		local projectile = pathToThePart
		projectile.Parent = workspace
		projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
		projectile.BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
		end
end)

I think you forgot to copy the first line.