So i tired to make a move where the character moves faster, here is the code:
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() Activate = false --Activate Mouse.KeyDown:connect(function(key) key = key:lower() if key ~= "z" then return end; if Activate == false then Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed +35 Activate = true end end) --Deactivation Mouse.KeyDown:connect(function(key) key = key:lower() if key ~= "z" then return end; if Activate == true then Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed -35 Activate = false end end)
So is there anyway, to make the activation and deactivation work?
There's no point in using two. Use an else statement to check if the bool is true or false.
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() Activate = false --Activate Mouse.KeyDown:connect(function(key) key = key:lower() if key ~= "z" then return end; if Activate == false then Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed +35 Activate = true else Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed -35 Activate = false end end)
This worked for me, however.
KeyDown is deprecated, as you will see on the wiki.
I'm not going to explain how UserInputService works. If you're confused, ask another question. However, first read the wiki on the subject.
With using UserInputService, the script looks more like this.
Player = game.Players.LocalPlayer Activate = false game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode ~= Enum.KeyCode.Z then return end if Activate == false then Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed +35 Activate = true else Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed -35 Activate = false end end)
Good Luck!