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

Shift to sprint on filtering enabled?

Asked by 6 years ago
Edited 6 years ago

I need help on a script that works on experimental mode but does not work on filtering enabled.

Here is the script just in case:

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

Thank You!

2 answers

Log in to vote
0
Answered by 6 years ago

Alright, first thing is first: do not use KeyDown or KeyUp, use UserInputService instead.

KeyDown and KeyUp are deprecated, which means they are no longer supported by Roblox and can be removed at any time.

Here is an example of getting input by using UserInputService:

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.Q then
        print("You pressed the Q key!")
    end
end)

It's nearly the same, but better.

Now, about FilteringEnabled. You can make changes to a player's humanoid with a local script and it will replicate to the server. So, that means your script should be working. However, since you stated that it is not a local script and you are using game.Players.LocalPlayer, there is your issue.

Simply change your script from a server script to a local script, and make sure to use UserInputService. Everything should work afterwards.

0
I want SHIFT not Q CraytiveWarrior 0 — 6y
0
I understand. This is just an example and you should be able to change it to your likings. Operation_Meme 890 — 6y
0
how do i make him stop running when i stop pressing the SHIFT? CraytiveWarrior 0 — 6y
0
Use the site chat please. Operation_Meme 890 — 6y
0
Only the Sit and Jump properties are replicated. The Walkspeed appears to be replicated because the client handles the physics of their character on their client. hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

The client has network ownership over their character.

The client has network ownership over their respective character, meaning that they can modify some aspects of their character, and still have the change replicated to the server. This means you can change your character's walkspeed locally, and won't have to worry about it not replicating.

Sample Code

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

local sprintWalkspeed, defaultWalkspeed = 34, 16
local sprintHotkey = Enum.KeyCode.LeftShift

local function ToggleWalkspeed(isInputBegan)
    player.Character.Humanoid.WalkSpeed = isInputBegan and sprintWalkSpeed or defaultWalkspeed
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == sprintHotkey then ToggleWalkspeed(true) end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessed)
    if input.KeyCode == sprintHotkey then ToggleWalkspeed(false) end
end)

Answer this question