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

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

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!

4 comments

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()

0

A previous question like this had this as an answer: http://wiki.roblox.com/index.php?title=Weapons

1

you should be using userinputservice. as far as im aware, KeyDown is deprecated in the way you're using it

0

^this^

1 answer

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!

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