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

How does one make it so if someone clicks a key twice something happens opposite to the first click?

Asked by
AizakkuZ 226 Moderation Voter
5 years ago
Edited 5 years ago

Okay, so I was told to try to make a script because one of my questions was asking how to do something instead of trying to make it myself then, asking and someone gave me a script so I looked through it and tried to add the same things to my own script. After this I look back then try to fixate any mistakes after I find out the user made a mistake so I fixed that. After I figured i'd try it on another script, it worked but it doesn't seem to work for this script. I figured out I had to make a variable that is 0 at default and adds one every time the key is clicked, after you tell the script that certain part of the script would make the variable = 1 then you tell it a certain part would make the variable = 2 and however many times u need it to count so I made this ```lua plr = game:GetService("Players").LocalPlayer char = plr.Character hum = char:WaitForChild("Humanoid") rad = math.rad s = char:WaitForChild('WhiteBlack') sw = s.Sword wc = s.Sword.Sword local w = Instance.new('Weld', sw) lh = char:WaitForChild('LeftHand') cero = script.Parent.Cero oof = script.Parent.HandToHand oof2 = script.Parent.SwordsManShip local Anim4 = Instance.new("Animation") Anim4.AnimationId = "http://www.roblox.com/Asset?ID=02919926374" local Anim4 = hum:LoadAnimation(Anim4) local dbounce = false local keys = 0

function onKeyDown(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Q and dbounce == false then dbounce = true keys = keys + 1 keys = 1 print("Q was pressed") Anim4:Play() wait(0.5) wc.Enabled = false sw.Parent = char w.Part0 = lh w.Part1 = sw w.C0 = CFrame.new(0,-0.2,-2) * CFrame.Angles(rad(0),rad(180),rad(90)) oof.Disabled = true oof2.Disabled = false cero.Disabled = true

function onKeyDown(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Q then keys = keys + 1 print("Q Pressed 2") end end wait()

while keys == 2 do Anim4:Play() oof.Disabled = false oof2.Disabled = true cero.Disabled = false w.Active = false wc.Enabled = true end end end game:GetService("UserInputService").InputBegan:connect(onKeyDown)

``` This basically welds a group to player then a part in that group is taken out this being a sword then placed near the LeftHand after it welds it to LeftHand and plays an animation before it changes.

That was the first click at least the second click does the opposite making the weld inactive and places it back where it was before.

Note that I get no errors from this script But, I do get the first print function ("Q Was Pressed") in output meaning the first part works; why isn't the second part working.?

0
I think you could combine the two functions into one and just add an "elseif" statement? Where are the "keys" stored? You could add a string/int whatever value into the player like a leaderstat if you want to keep track of them. ABK2017 406 — 5y
0
The "Keys" is just a variable to count up and the elseif i'll try that, thanks AizakkuZ 226 — 5y
0
The second function isn’t running because it has no reason to, the conditions are met with the first function every time, thats why I suggested something like an “elseif” ABK2017 406 — 5y
0
Oh AizakkuZ 226 — 5y

Answer this question