I'm trying to make this thing that when the player is jumping, they will be able to press space again to transform their character. Is there anything wrong with my script? the transform part is working, it's just when the player is jumping and is pressing the spacebar again.
if Humanoid.Jump == true then game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.Space then for _, child in pairs(script.Parent:GetChildren()) do is_transformed = true if child:IsA("UnionOperation") then child.CanCollide = false child.Transparency = 1 Animator.Parent = nil Humanoid.HipHeight = 1 end end end end) end
Here should be a way to do this:
local InputEvent local LandingEvent Humanoid.Jumping:Connect(function() local didSecondSpace = false if InputEvent ~= nil then InputEvent:Disconnect() end if LandingEvent ~= nil then LandingEvent:Disconnect() end InputEvent = game:GetService("UserInputService").InputBegan:Connect(function(input); if input.KeyCode == Enum.KeyCode.Space and didSecondSpace == false then didSecondSpace = true InputEvent:Disconnect() LandingEvent:Disconnect() for _, child in pairs(script.Parent:GetChildren()) do is_transformed = true if child:IsA("UnionOperation") then child.CanCollide = false child.Transparency = 1 Animator.Parent = nil Humanoid.HipHeight = 1 end end end end) LandingEvent = Humanoid.StateChanged:Connect(function(old, new) if new == Enum.HumanoidStateType.Landed and didSecondSpace == false then InputEvent:Disconnect() LandingEvent:Disconnect() end end) end
I just free-handed it, didn't test it. So uh, yeah.