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

Can someone tell me why when I press c it doesnt change my speed?

Asked by 5 years ago
Edited 5 years ago
local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local ls = game.Players.LocalPlayer:WaitForChild('leaderstats')
local power = ls.Power

    function PressC(key)    
    if (key == "c") then
        if power.Value == 'Super Speed' then do
            if Humanoid.WalkSpeed == 16 then
                Humanoid.WalkSpeed = 50
                script.Parent.Text = 'Click to Slow Down'
            elseif Humanoid.WalkSpeed == 50 then
                Humanoid.WalkSpeed = 16
                script.Parent.Text = 'Click to Speed Up'
            end
        end
        end

    end
        Mouse.KeyDown:connect(PressC)


When I press C it does not change my speed!

0
I think line 7 is wrong? Mousebutton1click is for a player's mouse not the player itself. Do this: Mouse = game.players.LocalPlayer:GetMouse() OBenjOne 190 — 5y
0
A previous question like this had this as an answer: http://wiki.roblox.com/index.php?title=Weapons OBenjOne 190 — 5y
1
you should be using userinputservice. as far as im aware, KeyDown is deprecated in the way you're using it Lugical 425 — 5y
0
^this^ Fifkee 2017 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Hi, I'm BlackOrange and today I will be helping you out.

Problem:

  1. You are manipulating Humanoid WalkSpeed on the Client
  2. You are using deprecated code (Keydown and :connect)

Solution:

Assuming your game is FilteringEnabled, you will need RemoteEvent

To Start: Add a Script into ServerScriptService

Now add a LocalScript to StarterCharacterScripts (It's in StarterPlayer)

Edit the Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) -- when a signal is recieved
    local Char = plr.Character or plr.CharacterAdded:Wait() -- get character
    local Humanoid = Char:WaitForChild('Humanoid')
    if Humanoid.WalkSpeed = 16 then
        Humanoid.WalkSpeed = 50
    else
        Humanoid.WalkSpeed = 16
    end
end)

Now in the local script:

local plr = game.Players.LocalPlayer

game.UserInputService.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end
    if Input.KeyCode == Enum.KeyCode.C then
        game.ReplicatedStorage.RemoteEvent:FireServer()
    end
end)

Hope this helped

Best of luck dev!

Ad

Answer this question