I'm trying to transform a player if a player press the spacebar and I want both of the function to have the same key, so when the player press the spacebar twice on the first time, it will transform the player. But if the player presses the spacebar once after it has already transformed, the player will come back to its original state.
KeyPressed = 0
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
for _, child in pairs(script.Parent:GetChildren()) do
KeyPressed = 2
if child:IsA("UnionOperation") then
child.CanCollide = false
child.Transparency = 1
Animator.Parent = nil
Humanoid.HipHeight = 1
end
end
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
for _, child in pairs(script.Parent:GetChildren()) do
KeyPressed = 1
if child:IsA("UnionOperation") then
child.CanCollide = false
child.Transparency = 0
Animator.Parent = Humanoid
Humanoid.HipHeight = 10.75
end
end
end
end)

2 comments
Yeah but, how do I make it so that the transform only happen when the key is pressed twice in a row?
You could increment a counter when the key is pressed