Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cannot make player sprint when a tool is equipped?

I can't seem to make players in my game sprint when they have a sword equipped, specifically when they press "E". I'll post the code that I have below, any help would be greatly appreciated!

sword = game.StarterPack.ClassicSword

sword.Equipped:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	
	local UserInputService = game:GetService("UserInputService")
	
	local eHeld = UserInputService:IsKeyDown(Enum.KeyCode.E)
	
	if eHeld == true then
		
	character.Humanoid.WalkSpeed = 20
		
	elseif eHeld == false then
		character.Humanoid.WalkSpeed = 16
		
	end
	
end)

1 comment

0

Get the backpack of the localplayer not starterpack, I'll make an answer for it right now

1 answer

Line 1,

sword = game.StarterPack.ClassicSword

You're trying to get the sword in the StarterPack, not the local player's backpack. Starterpack is for giving a player tools every time their character loads. Fixed script:

local sword = game.Players.LocalPlayer.Backpack:WaitForChild('ClassicSword') -- here

sword.Equipped:Connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character

    local UserInputService = game:GetService("UserInputService")

    local eHeld = UserInputService:IsKeyDown(Enum.KeyCode.E)

    if eHeld == true then

    character.Humanoid.WalkSpeed = 20

    elseif eHeld == false then
        character.Humanoid.WalkSpeed = 16

    end

end)

Hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.