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

Sprint script is not functioning properly?

the script is popping up in output with ServerScriptService.Sprint:2: attempt to indext local 'Player' (a nil value)

local Player = game.Players.LocalPlayer
local Mouse = Player.GetMouse()
local KeysDown = {}

Mouse.KeyDown:connect(function(Key)
	if Key:lower() == "w" then
		KeysDown["w"] = true
	elseif Key:byte() == 48 then
		KeysDown["Shift"] = true
	end
	
	if KeysDown["w"] and KeysDown["Shift"] then
		Player.Character.Humanoid.WalkSpeed = 32
	end
end)

Mouse.KeyUp:connect(function(Key)
	if Key:Lower() == "w" then
		KeysDown["w"] = false
	elseif Key:byte() == 48 then
		KeysDown["Shift"] = false
	end
	
	if not KeysDown["w"] or not KeysDown["Shift"] then
		Player.Character.Humanoid.WalkSpeed = 16
	end
end)

3 comments

0

Is that a script or a localscript?

0

its now local script

0

KeyDown is depricated becareful.

1 answer

✓ Accepted answer

It looks like you're using a server script that's inside ServerScriptService.

Copy all the contents of this script and make a new LocalScript and put it inside of 'StarterPlayerScripts' folder and then also change the top two lines of code to this:

local Player = game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Edit: Also the Player was nil because scripts can only access server-side events and properties and you were trying to access a local player which is client sided.

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