Hi, I'm extremely new to scripting and I would really appreciate if you all can answer why my code isn't working. I inserted a script into a part called FlyingObject which I wanted it to fall when a player presses a certain Key and then when they let go it would go back to normal.

Here are some more info:

  • I used a script instead of a LocalScript

  • The script's parent is the part mentioned above.

  • The part is anchored in the sky and is suppose fall then go back up once the player stops pressing E.

  • The part isn't even falling.

Here's my code:

UserInputService = game:GetService("UserInputService")
local FlyingObject = game.Workspace.FlyingObject

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.Keycode == Enum.KeyCode.E then
		FlyingObject.Anchored = false
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if input.Keycode == Enum.Keycode.E then 
		FlyingObject.Anchored = true
		FlyingObject.Position.X = (-11)
		FlyingObject.Position.Y = (9.5)
		FlyingObject.Position.Z = (-9)
	end
end)

Thank you for reading!