How add ability to player after he dies

Hello I am currently experiencing a minor problem. I made a dashing script that if you press left shift, it gives player speed for 10 seconds. But when player dies the script doesn’t work. No matter how much I press left shift it does nothing. I am give the video of dashing and the image of code. Please help me!

Video :

Image :

2 Likes

where is the script placed? usually anything in StarterGui or StarterScripts’ should be given back to the player upon respawning.

1 Like

Why do you have the “or player.CharacterAdded:Wait()” in the beginning?

This is a working sprint script i have:

local player = game.Players.LocalPlayer
local camera = game.Workspace.Camera

-- Used to start the sprint process (changing FOV and character speed)
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
    	for i = 1,16 do
    		wait()
    		camera.FieldOfView = camera.FieldOfView + 1.6
    		player.Character:WaitForChild("Humanoid").WalkSpeed = player.Character:WaitForChild("Humanoid").WalkSpeed + 1
		end
    end
end)

-- Used to end the sprint process (changing FOV and character speed)
game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
    	for i = 1,16 do
    		wait()
    		camera.FieldOfView = camera.FieldOfView - 1.6
    		player.Character:WaitForChild("Humanoid").WalkSpeed = player.Character:WaitForChild("Humanoid").WalkSpeed - 1
	    end
    end
end)

-- Reset the FOV and speed of the character if the character dies
pcall(function()
    player.Character:WaitForChild("Humanoid").Died:connect(function()
    		camera.FieldOfView = 70	
    		player.Character.Humanoid.WalkSpeed = 16
    	script.Disabled = true
    end)
end)
local player = game.Players.LocalPlayer
local character

local UIS = game:GetService("UserInputService")

local CoolingDown = false

player.CharacterAdded:Connect(function(plrchar)
	character = plrchar
end)

UIS.InputBegan:Connect(function(input, processed)

	if input.KeyCode == Enum.KeyCode.LeftShift and not processed then
	
	if CoolingDown then return end
	
	local HRP = character:FindFirstChild("HumanoidRootPart")
	
	if not HRP then return end
	
	CoolingDown = true
	
	for i = 300, -0, -3 do
	
	HRP.Velocity = HRP.CFrame.lookVector * if
	wait(.1)
	end
	
	wait(2)
	
	CoolingDown = false
	
	end
	
end)

I tried to fix your script. Basically you should make a global variable of the character every time the player character spawns. In the script you have now it creates a variable of the character once and after the character respawns that variable becomes nil. I hope this makes sense.

Put the script in StarterCharacterScripts and get the character with script.Parent. This is because when the player respawns, the humanoid in the script is no longer the same Humanoid, as a new one gets put in the player’s character when they respawn.

2 Likes

Omg it worked. Thank you so much