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

How do I make it so if a key is pressed, it does something,then if it's pressed again, it undos it?

Asked by 6 years ago

When someone presses z, they go into a giant form. I want to make it so if someone presses z again, they return to their original form. This is my code so far. I put Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value + 1 Player.Character.Humanoid.BodyHeightScale.Value = Player.Character.Humanoid.BodyHeightScale.Value + 1 Player.Character.Humanoid.BodyWidthScale.Value = Player.Character.Humanoid.BodyWidthScale.Value + 1 Player.Character.Humanoid.HeadScale.Value = Player.Character.Humanoid.HeadScale.Value + 1 a bunch of times because I want a smooth transition while they grow into a giant form.

local Player = game.Players.LocalPlayer
local char = Player.Character
local mouse = Player:GetMouse()
local cooldown = 0
local Humanoid = game.Players.LocalPlayer:FindFirstChild("Humanoid")
mouse.KeyDown:connect(function(k)
    k = k:lower()
    if k == "z" and cooldown == 0 then
        cooldown = 1
        Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value + 1
        Player.Character.Humanoid.BodyHeightScale.Value = Player.Character.Humanoid.BodyHeightScale.Value + 1
        Player.Character.Humanoid.BodyWidthScale.Value = Player.Character.Humanoid.BodyWidthScale.Value + 1
        Player.Character.Humanoid.HeadScale.Value = Player.Character.Humanoid.HeadScale.Value + 1
        wait()
        Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value + 1
        Player.Character.Humanoid.BodyHeightScale.Value = Player.Character.Humanoid.BodyHeightScale.Value + 1
        Player.Character.Humanoid.BodyWidthScale.Value = Player.Character.Humanoid.BodyWidthScale.Value + 1
        Player.Character.Humanoid.HeadScale.Value = Player.Character.Humanoid.HeadScale.Value + 1
        wait()
        Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value + 1
        Player.Character.Humanoid.BodyHeightScale.Value = Player.Character.Humanoid.BodyHeightScale.Value + 1
        Player.Character.Humanoid.BodyWidthScale.Value = Player.Character.Humanoid.BodyWidthScale.Value + 1
        Player.Character.Humanoid.HeadScale.Value = Player.Character.Humanoid.HeadScale.Value + 1
        wait()
        Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value + 1
        Player.Character.Humanoid.BodyHeightScale.Value = Player.Character.Humanoid.BodyHeightScale.Value + 1
        Player.Character.Humanoid.BodyWidthScale.Value = Player.Character.Humanoid.BodyWidthScale.Value + 1
        Player.Character.Humanoid.HeadScale.Value = Player.Character.Humanoid.HeadScale.Value + 1
    end
end)
0
User a bool variable (Something like IsAGiant) that would change when the player presses the key. You should also be using UserInputService for input and not the Mouse functions. xPolarium 1388 — 6y
0
Thank you so much!!!! Timbawolf1 6 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Use a boolean. Also, please put your grow code in a function and repeat the function instead of copypasting the code over and over again

0
How do I do that? Timbawolf1 6 — 6y
0
basically, a function allows you to insert code into it and call the function. when you call it, it will run the code inside. To make a function, just write "function putFunctionNameHere()" and to close it write "end". Put the code in there and call it like so: "putFunctionNameHere()" ronitrocket 120 — 6y
Ad

Answer this question