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)
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