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

Key still not working/broken?

Asked by
Hero_ic 502 Moderation Voter
10 years ago

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

01local mode = 0 -- 0 = default, 1 = battle.
02local gyro = Instance.new('BodyGyro')
03gyro.maxTorque = Vector3.new(1400000,1400000,1400000)
04wait()
05local cFrame = CFrame.new(0, 0, 0)
06local torso = player.Character.Torso
07 
08mouse.KeyDown:connect(function(key)
09    if mode == 0 then
10gyro.Parent = game.Lighting
11    if string.byte(key) == 48 then
12    mode = 1
13    end
14end
15 
View all 29 lines...
1
If your problem is fixed, please do not delete the question! You can post additional questions, so there is no value in deleting your question! Unclear 1776 — 10y
0
I'm very sorry i will not do this again, i'm new here so i got a lot to learn. Hero_ic 502 — 10y
0
I still need help though as i have been trying to fix this for hours. :/ Hero_ic 502 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

You should probably use elseif mode == 1 then. But if you want to hold the key and release it to stop you do this.

01mouse.KeyUp:connect(function(key)
02 
03    if string.byte(key) == 48 then
04        mode = 1
05        gyro.Parent = game.Lighting
06    end
07end)
08 
09mouse.KeyDown:connect(function(key)
10 
11    if string.byte(key) == 48 then
12        mode = 0
13        gyro.Parent = torso
14    end
15end)
0
Thanks i guess i'll just go with holding the key instead of tapping it :) Hero_ic 502 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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.

01local mode = 0 -- 0 = default, 1 = battle.
02local gyro = Instance.new('BodyGyro')
03gyro.maxTorque = Vector3.new(1400000,1400000,1400000)
04wait()
05local cFrame = CFrame.new(0, 0, 0)
06local torso = player.Character.Torso
07 
08mouse.KeyDown:connect(function(key)
09    if mode == 0 then
10gyro.Parent = game.Lighting
11    if string.byte(key) == 48 then
12    mode = 1
13    end
14end
15 
View all 21 lines...
0
it still does not work :/ oh well. Hero_ic 502 — 10y

Answer this question