Problems with UserInputService

I was trying to make an attack for this tool using UserInputService and I ran Into a Problem. the tool doesn’t do the move

------------------Main-----------------
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Handle)
local uis = game:GetService("UserInputService")
Hitbox.Visualizer = true
local CurrentHumnanoid
local idle
local CurrentAnimation
local CurrentAnimation2
local CurrentAnimation3
local Spin
local db = true
local click = 0
------------------ShortNames-----------
local tool = script.Parent
local char = tool.Parent
local handle = tool:FindFirstChild("Handle")
local T = 1
local Dmg = 19.75
local cd = .7
------------------functions------------

script.Parent.Activated:Connect(function()
	if db then
		db = false

		click += 1
		if click == 1 then
			Hitbox:HitStart(.55)
			if CurrentAnimation then
				CurrentAnimation:Play()
			end
		elseif click == 2 then
			Hitbox:HitStart(.55)
			if CurrentAnimation2 then
				CurrentAnimation2:Play()
				click = 0
			end
		end
		wait(cd)
		db = true
	end
end)

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if db then
		db = false
		if input.KeyCode == Enum.KeyCode.E then
			Hitbox:Hitstart(2)
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpHeight = 0
			if Spin then
				Spin:Play()
				task.wait(2)
				char.Humanoid.WalkSpeed = 16
				char.Humanoid.JumpHeight = 7.2
			end
		end
		task.wait(8)
		db = true
	end
end)

Hitbox.OnHit:Connect(function(Part, Humanoid)
	if Humanoid and Humanoid ~= script.Parent.Parent.Humanoid then
		Humanoid:TakeDamage(Dmg)
	end
end)

tool.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
	if Humanoid and Humanoid ~= CurrentHumnanoid then
		CurrentHumnanoid = Humanoid
		idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
		idle.Priority = Enum.AnimationPriority.Action
		idle.Looped = true
		idle:Play()
		CurrentAnimation = Humanoid.Animator:LoadAnimation(script.Slash)
		CurrentAnimation2 = Humanoid.Animator:LoadAnimation(script.Slash2)
		Spin = Humanoid.Animator:LoadAnimation(script.Spin)
	end
end)

script.Parent.Unequipped:Connect(function()

end)

here is UserInputService part. Did I type something wrong?

Have you tried debugging? (using print())

I haven’t Tried that yet
(char limit)

Try putting it above the if db then and see if it works then try one above db = false then try below if input.keycode

See if you get all the prints go through

Ok so It didn’t even print

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.Q then
		print("dasdsa")
		if db then
			db = false
			Hitbox:Hitstart(2)
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpHeight = 0
			if Spin then
				Spin:Play()
				wait(2)
				char.Humanoid.WalkSpeed = 16
				char.Humanoid.JumpHeight = 7.2
				end
		end
		wait(8)
		db = true
	end
end)

Wait, this is inside a server script isnt it?
things like this only work in local scripts

ye it is inside server script. I didn’t know if that only worked in local scripts then what do I have to do so it works for server side

Its possible that, as korbukobs said, it is in the wrong type of script.
Atlernatively, trying making the function seperate

for example

local function UserInput(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Q then
		print("dasdsa")
		if db then
			db = false
			Hitbox:Hitstart(2)
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpHeight = 0
			if Spin then
				Spin:Play()
				wait(2)
				char.Humanoid.WalkSpeed = 16
				char.Humanoid.JumpHeight = 7.2
				end
		end
		wait(8)
		db = true
	end
end
uis.InputBegan:Connect(UserInput)

copy and paste the script into a local script, and put it in StarterPlayerScripts

Create a local script inside of the tool and put a remote event inside the tool too then inside the local script type:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent == false then
		script.Parent.RemoteEvent:FireServer(input.KeyCode)
	end
end)

Then inside the sever script replace the inputbegans with:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(caller, keyCode)
	--code here
end)
2 Likes

So I tried that but either I am dumb or its not working

Server:

------------------Main-----------------
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Handle)
local uis = game:GetService("UserInputService")
Hitbox.Visualizer = true
local CurrentHumnanoid
local idle
local CurrentAnimation
local CurrentAnimation2
local CurrentAnimation3
local Spin
local db = true
local click = 0
------------------ShortNames-----------
local tool = script.Parent
local char = tool.Parent
local handle = tool:FindFirstChild("Handle")
local T = 1
local Dmg = 19.75
local cd = .7
------------------functions------------

script.Parent.Activated:Connect(function()
	if db then
		db = false

		click += 1
		if click == 1 then
			Hitbox:HitStart(.55)
			if CurrentAnimation then
				CurrentAnimation:Play()
			end
		elseif click == 2 then
			Hitbox:HitStart(.55)
			if CurrentAnimation2 then
				CurrentAnimation2:Play()
				click = 0
			end
		end
		wait(cd)
		db = true
	end
end)

script.Parent.RemoteEvent.OnServerEvent:Connect(function(keyCode)
	if keyCode == Enum.KeyCode.Q then
		if db then
			db = false
			Hitbox:Hitstart(2)
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpHeight = 0
			if Spin then
				Spin:Play()
				wait(2)
				char.Humanoid.WalkSpeed = 16
				char.Humanoid.JumpHeight = 7.2
			end
		end
		wait(8)
		db = true
	end
end)

Hitbox.OnHit:Connect(function(Part, Humanoid)
	if Humanoid and Humanoid ~= script.Parent.Parent.Humanoid then
		Humanoid:TakeDamage(Dmg)
	end
end)

tool.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
	if Humanoid and Humanoid ~= CurrentHumnanoid then
		CurrentHumnanoid = Humanoid
		idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
		idle.Priority = Enum.AnimationPriority.Action
		idle.Looped = true
		idle:Play()
		CurrentAnimation = Humanoid.Animator:LoadAnimation(script.Slash)
		CurrentAnimation2 = Humanoid.Animator:LoadAnimation(script.Slash2)
		Spin = Humanoid.Animator:LoadAnimation(script.Spin)
	end
end)

script.Parent.Unequipped:Connect(function()

end)

Client:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent == false then
		script.Parent.RemoteEvent:FireServer(input.KeyCode)
	end
end)

Tool:
https://gyazo.com/b47684f7212ab97106ef220f396d79c1

Try printing now, sorry for the late reply

Its ok, this is the right place to place print right?

script.Parent.RemoteEvent.OnServerEvent:Connect(function(KeyCode)
	if KeyCode == Enum.KeyCode.Q then
		print("dsa")
		if db then
			db = false
			Hitbox:Hitstart(2)
			char.Humanoid.WalkSpeed = 0
			char.Humanoid.JumpHeight = 0
			if Spin then
				Spin:Play()
				wait(2)
				char.Humanoid.WalkSpeed = 16
				char.Humanoid.JumpHeight = 7.2
			end
		end
		wait(8)
		db = true
	end
end)

and if it is It didn’t print

Oh sorry, my mistake:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(caller, KeyCode)

1 Like

It works thanks for your help :smiley: