Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sprint script is not functioning properly?

Asked by 6 years ago

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)
0
Is that a script or a localscript? OfcPedroo 396 — 6y
0
its now local script skillfulzombie88 28 — 6y
0
KeyDown is depricated becareful. Mr_MilkysButler 47 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question