Keys not being detected in this script

Hello! It’s me again!

I can’t seem to get the keyboard/gamepad part of this to work.

The keys don’t even get detected, on both my XBOX One gamepad and keyboard.

--call objects--
local IceBalloon = script.Parent.Parent.Model.MeshPart
local IceTrig = script.Parent
local Attach = script.Parent.Parent.Model.ee.Attachment1
local IDLE_SWING = script.Parent.Parent.ANIMS.Animation
local defaultGravity = 196.2
local SwingGravity = 55
local UserInputService = game:GetService("UserInputService")
--end of calling objects--


--script start--
local function PlayerTouched(Part) 
		local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		
		workspace.Gravity = SwingGravity
		
		Parent.Archivable = true
		
		local PLY_ATTACH = Instance.new("Attachment")
		PLY_ATTACH.Parent = Parent.Head
		
		local CREATE_ROPE = Instance.new("RopeConstraint")
		CREATE_ROPE.Attachment0 = PLY_ATTACH
		CREATE_ROPE.Attachment1 = Attach
		CREATE_ROPE.Length = 10
		CREATE_ROPE.Restitution = 0.2
		CREATE_ROPE.Parent = Parent.Head
		CREATE_ROPE.Thickness = 0.5
		CREATE_ROPE.Visible = true
		CREATE_ROPE.Color = BrickColor.new("Carnation pink")
		
local Play_IDLE_SWING = Parent.Humanoid:LoadAnimation(IDLE_SWING)
Play_IDLE_SWING:Play()
		
		IceTrig.Size = Vector3.new(0.2, 0.2, 0.2)
		
			--CHECK FOR XBOX INPUTS--
			UserInputService.InputBegan:Connect(function(input)
				if input.UserInputType == Enum.UserInputType.Gamepad1 then
					if input.KeyCode == Enum.KeyCode.ButtonA then
						--PLAYER EXIT SWING STATE--
						CREATE_ROPE:Destroy()
						workspace.Gravity = defaultGravity
						PLY_ATTACH:Destroy()
						
					--END OF XBOX--
					
			--CHECK FOR PC INPUTS--
			local function onInputBegan(input, gameProcessed)
				if input.UserInputType == Enum.UserInputType.Keyboard then
					if input.KeyCode == Enum.KeyCode.Space then
						--PLAYER EXIT SWING STATE--
						print("test")
						CREATE_ROPE:Destroy()
						workspace.Gravity = defaultGravity
						PLY_ATTACH:Destroy()
						
			--END OF PC--
			
							end	
						end
					end
				end
			end
		end)
	end
end

script.Parent.Touched:connect(PlayerTouched) 
2 Likes

You haven’t called onInputBegan and you also need to change where you put your ends. Maybe the best option would be to go back and learn from some tutorials or something

Thank you. Do you have an example?

Check out the code example at the bottom. Notice how the ends are positioned relative to the ifs and functions.