Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

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.

0

Thank you so much!!!!

1 answer

✓ Accepted answer

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

2 comments

0

How do I do that?

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()"

This discussion is preserved as it was. New answers, comments, and votes are closed.