As you can see my problem is that once the player presses the shift key he should follow the mouse and once he presses it again he should stop following the mouse and move normally after this, but it seems that if i press any key but shift it deactivates the player following mouse script again after i activate it with shift again. You can try this script yourself by putting
local mode = 0 -- 0 = default, 1 = battle. local gyro = Instance.new('BodyGyro') gyro.maxTorque = Vector3.new(1400000,1400000,1400000) wait() local cFrame = CFrame.new(0, 0, 0) local torso = player.Character.Torso mouse.KeyDown:connect(function(key) if mode == 0 then gyro.Parent = game.Lighting if string.byte(key) == 48 then mode = 1 end end if mode == 1 then gyro.Parent = torso if string.byte(key) == 48 then mode = 0 end end game:GetService("RunService").RenderStepped:connect(function() local position = mouse.Hit.p local setPosition = Vector3.new(position.X, torso.Position.Y, position.Z) local direction = (setPosition - torso.Position).unit cFrame = CFrame.new(torso.Position, torso.Position + direction) gyro.cframe = cFrame end)
You should probably use elseif mode == 1 then. But if you want to hold the key and release it to stop you do this.
mouse.KeyUp:connect(function(key) if string.byte(key) == 48 then mode = 1 gyro.Parent = game.Lighting end end) mouse.KeyDown:connect(function(key) if string.byte(key) == 48 then mode = 0 gyro.Parent = torso end end)
Im pretty sure your problem is where you check "if" mode == () then: use elseif in order to run both of them if the first one is incorrect.
local mode = 0 -- 0 = default, 1 = battle. local gyro = Instance.new('BodyGyro') gyro.maxTorque = Vector3.new(1400000,1400000,1400000) wait() local cFrame = CFrame.new(0, 0, 0) local torso = player.Character.Torso mouse.KeyDown:connect(function(key) if mode == 0 then gyro.Parent = game.Lighting if string.byte(key) == 48 then mode = 1 end end elseif mode == 1 then gyro.Parent = torso if string.byte(key) == 48 then mode = 0 end end