I am trying to make a press "e" to sprint script, but it says in the output: Players.rieleyhunt.Backpack.LocalScript:9: attempt to index upvalue 'character' (a nil value)
I am new to localscripts so please keep it easy for me
player = game.Players.LocalPlayer playerMouse = player:GetMouse() local character = player.Character playerMouse.KeyDown:Connect(function(key) if key == "e" then character.Humanoid.WalkSpeed = 50 end end)
Thanks
playerMouse = player:GetMouse() playerMouse.KeyDown:Connect(function(key) if key == "e" then game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 50 end end)
Variables will save objects as the state they were in when they were saved. The problem is probably that the player object loads in before the character, since there's no character the value will be stored as "nil", basically nothing. To solve this i simply removed the "character" and "player" variables and instead used the current state of the character and player, the "raw" state if you could call it that.