local s={}function s.GetActionInput(s,m)local h="\110\105\108"if actions[m]then local s,f=actions[m].Primary,actions[m].Secondary if s then h=s.Name elseif f then h=f.Name end end if REPLACEMENTS[h]then h=REPLACEMENTS[h]end return string.upper(h)end function s.GetAllActionInputs(s,m)local h,f="\110\105\108","\110\105\108"if actions[m]then local s,S=actions[m].Primary,actions[m].Secondary if s then h=s.Name end if S then f=S.Name end end if REPLACEMENTS[h]then h=REPLACEMENTS[h]end if REPLACEMENTS[f]then f=REPLACEMENTS[f]end return string.upper(h),string.upper(f)end if not initialized then local m=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")s.KeybindChanged=m.Event actionBegan=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")actionEnded=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")s.ActionBegan=actionBegan.Event s.ActionEnded=actionEnded.Event local h=PLAYER_DATA:WaitForChild(PLAYER.Name)local f=h:WaitForChild("\075\101\121\098\105\110\100\115")local function S(s,h,f)local S,I if h then local s,m=string.match(h,"\040\046-\041\037\046\040\046\043\041")if s and m then S=Enum[s][m]end end if f then local s,m=string.match(f,"\040\046-\041\037\046\040\046\043\041")if s and m then I=Enum[s][m]end end RegisterAction(s,S,I)m:Fire(s)end local function I(s)local m=s.Name local h=s.Value if string.match(h,"\059")then local s,f=string.match(h,"\040\046-\041\059\040\046\043\041")if s and f then S(m,s,f)elseif s then S(m,s)elseif f then S(m,nil,f)end else S(m,h)end end f.ChildAdded:connect(function(s)s.Changed:connect(function()I(s)end)RunService.Stepped:wait()I(s)end)repeat RunService.Stepped:wait()until#f:GetChildren()>0 for s,m in pairs(f:GetChildren())do m.Changed:connect(function()I(m)end)I(m)end initialized=true end return s


local INPUT	= {}

function INPUT.GetActionInput(self, action)
	local input	= "nil"
	
	if actions[action] then
		local primary, secondary	= actions[action].Primary, actions[action].Secondary
		
		if primary then
			input	= primary.Name
		elseif secondary then
			input	= secondary.Name
		end
	end
	
	if REPLACEMENTS[input] then
		input	= REPLACEMENTS[input]
	end
	
	return string.upper(input)
end

function INPUT.GetAllActionInputs(self, action)
	local inputP, inputS	= "nil", "nil"
	
	if actions[action] then
		local primary, secondary	= actions[action].Primary, actions[action].Secondary
		
		if primary then
			inputP	= primary.Name
		end
		if secondary then
			inputS	= secondary.Name
		end
	end
	
	if REPLACEMENTS[inputP] then
		inputP	= REPLACEMENTS[inputP]
	end
	if REPLACEMENTS[inputS] then
		inputS	= REPLACEMENTS[inputS]
	end
	
	return string.upper(inputP), string.upper(inputS)
end

if not initialized then
	local keybindChanged	= Instance.new("BindableEvent")
	INPUT.KeybindChanged	= keybindChanged.Event
	
	actionBegan	= Instance.new("BindableEvent")
	actionEnded	= Instance.new("BindableEvent")
	
	INPUT.ActionBegan	= actionBegan.Event
	INPUT.ActionEnded	= actionEnded.Event
	
	-- register actions
	
	local playerData	= PLAYER_DATA:WaitForChild(PLAYER.Name)
	local keybinds		= playerData:WaitForChild("Keybinds")
	
	local function Register(action, bindP, bindS)
		local primary, secondary
		if bindP then
			local A, B	= string.match(bindP, "(.-)%.(.+)")
			
			if A and B then
				primary	= Enum[A][B]
			end
		end
		if bindS then
			local A, B	= string.match(bindS, "(.-)%.(.+)")
			
			if A and B then
				secondary	= Enum[A][B]
			end
		end
		
		RegisterAction(action, primary, secondary)
		keybindChanged:Fire(action)
	end
	
	local function Handle(keybind)
		local action	= keybind.Name
		local bind		= keybind.Value
		
		if string.match(bind, ";") then
			local bindP, bindS	= string.match(bind, "(.-);(.+)")
			
			if bindP and bindS then
				Register(action, bindP, bindS)
			elseif bindP then
				Register(action, bindP)
			elseif bindS then
				Register(action, nil, bindS)
			end
		else
			Register(action, bind)
		end
	end
	
	keybinds.ChildAdded:connect(function(keybind)
		keybind.Changed:connect(function()
			Handle(keybind)
		end)
		
		RunService.Stepped:wait()
		Handle(keybind)
	end)
	
	repeat
		RunService.Stepped:wait()
	until #keybinds:GetChildren() > 0
	
	for _, keybind in pairs(keybinds:GetChildren()) do
		keybind.Changed:connect(function()
			Handle(keybind)
		end)
		
		Handle(keybind)
	end
	
	initialized			= true
end

return INPUT
