UIS suddenly stopped working overnight, and animations do not play

Hey developers. I’ve lost count how many posts on here I’ve made now - definitely a lot since I started this project - but I’m starting to regret making a battlegrounds game.

But, giving up is unlike me, so here I am, requesting some help. UserInputService has seemingly stopped detecting mouse clicks, despite it working fine last time I playtested the game.


As you can see, the enemy is inside the hitbox, yet clicking does nothing. No prints in console, no damage, nothing. I know it can’t be an issue with the hitbox, and has to be with the client as the prints that should count how many times the player has punched aren’t being printed out.

Here’s my client side code (in StarterCharacterScripts):

local punchEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("PunchEvent")
local walkspeedChanger = game:GetService("ReplicatedStorage").Events:WaitForChild("WalkspeedChanger")
local UIS = game:GetService("UserInputService")
local punchInput = Enum.UserInputType.MouseButton1
local players = game:GetService("Players")
local attacking = false
local count = 0
local oldCount
local alreadyHit = { }
local char = players.LocalPlayer.Character
local MokouFireHandler = game.ReplicatedStorage.Events.MokouFireHandler
local resetTime = 2
local CharacterData = game.Players.LocalPlayer.CharacterData

local animLength = 0.5 
local animLength2 = 1
local animator = char.Humanoid.Animator
local Animations = game.ReplicatedStorage.Animations
local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
	Sen = { },
	Sakuya = { }
}
local moveset: { Animation }? = MOVESET_ANIMATIONS[CharacterData.Moveset]
if not moveset then
	return
end
local punchAnimations: { AnimationTrack } = {}
for index: number, animation: Animation in moveset do
	punchAnimations[index] = animator:LoadAnimation(animation)
end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == punchInput then
		if attacking == true then print("Already punching!")
		elseif attacking == false then
			count = count + 1
			currentTime = tick()
			print("M1 count is now "..count)
			punchAnimations[count].Priority = Enum.AnimationPriority.Action
			punchAnimations[count]:Play()
			char.M1Box.CanTouch = true
			attacking = true
			if count <= 3 then
				task.wait(animLength)
				char.M1Box.CanTouch = false
				attacking = false
			elseif count >= 4 then
				walkspeedChanger:FireServer(count, animLength2)
				task.wait(animLength2)
				char.M1Box.CanTouch = false
				attacking = false
				count = 0
			end
		end
	end
end)

task.spawn(function()
	while true do
		task.wait(0.25)
		if count > 0 then
			if tick() - currentTime >= resetTime then
				count = 0
			end
		end
	end
end)

char.M1Box.Touched:Connect(function(hit)
	print("touch event fired")
	if hit.Parent.Humanoid ~= nil then
		print("humanoid exists!")
		if not table.find(alreadyHit, hit.Parent.Humanoid) then
			print("it's not in the table, inserting")
			table.insert(alreadyHit, hit.Parent.Humanoid)
			print("Event passing...")
			punchEvent:FireServer(hit.Parent.Humanoid, count)
			print("Event sent!")
			task.wait(animLength)
			table.remove(alreadyHit, table.find(alreadyHit, hit.Parent.Humanoid)) -- OH MY GOD WHY ISNT THIS BUILT INTO THE FUNCTION
			print("Removed")
		end
	end
end)

and here is my server code:

local punchEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("PunchEvent")
local WalkspeedChanger = game:GetService("ReplicatedStorage").Events:WaitForChild("WalkspeedChanger") --might be unneeded but i can't test that so here it is... sigh
local RagdollController = require(game:GetService("ServerStorage").RagdollController)
local MokouFireHandler = game.ReplicatedStorage.Events.MokouFireHandler

punchEvent.OnServerEvent:Connect(function(plr, targetHum, count, force)
	print("Event successfully passed, and recieved on the server!")
	local plrChar = plr.Character
	print("Attempting to damage the hit person")
	if count == 1 or count == 2 then
		targetHum.Health -= 3
	elseif count == 3 then
		targetHum.Health -= 4
	elseif count == 4 then
		targetHum.Health -= 4
		
		local Force = (plrChar.HumanoidRootPart.CFrame.LookVector * 15) + Vector3.new(0,math.random(1, 5), 0) -- still doesnt work :<<
		
		targetHum.Parent.HumanoidRootPart:ApplyImpulse(Force)
		RagdollController:Start(targetHum.Parent)
		task.wait(3)
		RagdollController:Stop(targetHum.Parent)
	elseif count >= 5 then
		print("how the hell")
	end
end)

WalkspeedChanger.OnServerEvent:Connect(function(plr, count, waitTime)
	if count == 4 then --double check (wont prevent exploiting anyways but whatever...)
		plr.Character.Humanoid.WalkSpeed = 0
		task.wait(waitTime + 0.3)
		plr.Character.Humanoid.WalkSpeed = 32
	end
end)

Also, it should be noted my animations don’t seem to play either, but that’s less important and can be solved another time.

Any help would be greatly appreciated.

This could be a failure point since findfirstchild isn’t used. (just spitballing here)
Have we tried scrolling up in the console? (There may be an error that occured earlier (possibly even in an unrelated script))
Have we tried checking cantouch is on by default?

  • There is no error farther up in the console or in any other scripts
  • Changing this to FindFirstChild yielded no results
  • CanTouch is indeed on.

I also know for a fact the .Touched function is not the issue, as the script would print if the InputBegan function was firing. This means the issue lies somewhere with that function - maybe MouseButton1 isn’t a correct reference in UserInputType, but I’m not sure. Or UIS is just broken right now, but that seems really, really unlikely.

Maybe you should use error instead of return if moveset happens to be undefined.

wait hold up, is this a module script??? (why return???)

regardless wether it is a module, you should print("sanity check") to see which lines up to the touched event connecting did the script fail.

It’s not a module. Not sure why return is there. I might have just been really tired while coding this.

I now get this error:
image

I assume in relevance to this snippet of code:

local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
	Sen = { },
	Sakuya = { }
}
local moveset: { Animation }? = MOVESET_ANIMATIONS[CharacterData.Moveset]
if not moveset then
	print("Moveset not found!")
end
local punchAnimations: { AnimationTrack } = {}
for index: number, animation: Animation in moveset do
	punchAnimations[index] = animator:LoadAnimation(animation)
end

Have you figured out the problem by yourself yet?

CharacterData.Moveset is something invalid. Check it and see why it’s like that. Maybe you could inform us. Is it a StringValue instance? You need to access its value using StringValue.Value, otherwise you’re doing basically MOVESET_ANIMATIONS[Instance.new("StringValue")].

Since we (I assume) found where the problem actually is, can we print CharacterData.Moveset to see it’s value just to make sure?
Have we tried table.freeze({...}) (including the ())

Additionally try MOVESET_ANIMATIONS["Mokou"] (or another key) just to make sure dictionary works as expected.

Is Moveset does exist ?
You could be just StringValue.Value

Hey, it seems like this problem is taking a while to solve.

My assumption after removing the CharacterData, Animations and Hitbox from the code so I can test it myself is that the suspected scope, UIS InputBegan event, is not the problem, as it worked normally.

Basically, this works:

local UIS = game:GetService("UserInputService")
local punchInput = Enum.UserInputType.MouseButton1
local players = game:GetService("Players")
local attacking = false
local count = 0
local oldCount
local alreadyHit = { }
local char = players.LocalPlayer.Character
local resetTime = 2
--local CharacterData = game.Players.LocalPlayer.CharacterData

local animLength = 0.5 
local animLength2 = 1
local animator = char.Humanoid.Animator
--local Animations = game.ReplicatedStorage.Animations
--local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
--	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
--	Sen = { },
--	Sakuya = { }
--}
--local moveset: { Animation }? = MOVESET_ANIMATIONS[CharacterData.Moveset]
--if not moveset then
--	error("Moveset not found!")
--end
--local punchAnimations: { AnimationTrack } = {}
--for index: number, animation: Animation in moveset do
--	punchAnimations[index] = animator:LoadAnimation(animation)
--end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == punchInput then
		if attacking == true then 
			print("Already punching!")
		elseif attacking == false then
			count = count + 1
			currentTime = tick()
			print("M1 count is now "..count)
			--punchAnimations[count].Priority = Enum.AnimationPriority.Action
			--punchAnimations[count]:Play()
			--char.M1Box.CanTouch = true
			attacking = true
			if count <= 3 then
				task.wait(animLength)
				--char.M1Box.CanTouch = false
				attacking = false
			elseif count >= 4 then
				task.wait(animLength2)
				--char.M1Box.CanTouch = false
				attacking = false
				count = 0
			end
		end
	end
end)

task.spawn(function()
	while true do
		task.wait(0.25)
		if count > 0 then
			if tick() - currentTime >= resetTime then
				count = 0
			end
		end
	end
end)

--char.M1Box.Touched:Connect(function(hit)
--	print("touch event fired")
--	if hit.Parent.Humanoid ~= nil then
--		print("humanoid exists!")
--		if not table.find(alreadyHit, hit.Parent.Humanoid) then
--			print("it's not in the table, inserting")
--			table.insert(alreadyHit, hit.Parent.Humanoid)
--			print("Event passing...")
--			punchEvent:FireServer(hit.Parent.Humanoid, count)
--			print("Event sent!")
--			task.wait(animLength)
--			table.remove(alreadyHit, table.find(alreadyHit, hit.Parent.Humanoid)) -- OH MY GOD WHY ISNT THIS BUILT INTO THE FUNCTION
--			print("Removed")
--		end
--	end
--end)

I also took my time implementing the hitbox again, so the only things that aren’t included in my modified version of your script are: Animations and CharacterData. This is the version with hitbox:

local UIS = game:GetService("UserInputService")
local punchInput = Enum.UserInputType.MouseButton1
local players = game:GetService("Players")
local attacking = false
local count = 0
local oldCount
local alreadyHit = { }
local char = players.LocalPlayer.Character
local resetTime = 2
--local CharacterData = game.Players.LocalPlayer.CharacterData

local animLength = 0.5 
local animLength2 = 1
local animator = char.Humanoid.Animator
--local Animations = game.ReplicatedStorage.Animations
--local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
--	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
--	Sen = { },
--	Sakuya = { }
--}
--local moveset: { Animation }? = MOVESET_ANIMATIONS[CharacterData.Moveset]
--if not moveset then
--	error("Moveset not found!")
--end
--local punchAnimations: { AnimationTrack } = {}
--for index: number, animation: Animation in moveset do
--	punchAnimations[index] = animator:LoadAnimation(animation)
--end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == punchInput then
		if attacking == true then 
			print("Already punching!")
		elseif attacking == false then
			count = count + 1
			currentTime = tick()
			print("M1 count is now "..count)
			--punchAnimations[count].Priority = Enum.AnimationPriority.Action
			--punchAnimations[count]:Play()
			char.M1Box.CanTouch = true
			attacking = true
			if count <= 3 then
				task.wait(animLength)
				char.M1Box.CanTouch = false
				attacking = false
			elseif count >= 4 then
				task.wait(animLength2)
				char.M1Box.CanTouch = false
				attacking = false
				count = 0
			end
		end
	end
end)

task.spawn(function()
	while true do
		task.wait(0.25)
		if count > 0 then
			if tick() - currentTime >= resetTime then
				count = 0
			end
		end
	end
end)

char.M1Box.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not table.find(alreadyHit, hit.Parent.Humanoid) then
			table.insert(alreadyHit, hit.Parent.Humanoid)
			punchEvent:FireServer(hit.Parent.Humanoid, count, LAST_PUNCH_KNOCKBACK, LAST_PUNCH_UPWARDS_KNOCKBACK)
			task.wait(animLength)
			table.remove(alreadyHit, table.find(alreadyHit, hit.Parent.Humanoid)) -- OH MY GOD WHY ISNT THIS BUILT INTO THE FUNCTION
		end
	end
end)

That version considers that the hitbox is initially setup for every player in a ServerScript with the following code:

-- This code is purely debug-only and is not optimized for game development

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local hitbox = Instance.new("Part")
		hitbox.Parent = character
		hitbox.Name = "M1Box"
		hitbox.Position = character:FindFirstChild("HumanoidRootPart").CFrame.Position + Vector3.new(0, 0, -3)
		hitbox.Anchored = false
		hitbox.CanCollide = false
		hitbox.CanTouch = false
		
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = character:FindFirstChild("HumanoidRootPart")
		weld.Part1 = hitbox
		weld.Parent = hitbox
	end)

	plr.CharacterRemoving:Connect(function(character)
		if character:FindFirstChild("M1Box") then
			character:FindFirstChild("M1Box"):Destroy()
		end
	end)
end)

With that code, your hitbox and UIS system should both be working fine. A few addition, you’re using .Touched() which is not recommended for hitboxes, specially ones that only need a single check and done. You currently need to turn .CanTouch on and off multiple times, which is not efficient nor works better for readability. If I was to choose something for this, I’d use workspace:GetPartBoundsInBox(). In basical form, you give it a Position and a Size, and it returns an array of whatever instances are currently inside that box. There are some other optimizations that I won’t touch due to possible opinion on code design.


After the previous test, I tested animations:

local UIS = game:GetService("UserInputService")
local punchInput = Enum.UserInputType.MouseButton1
local players = game:GetService("Players")
local attacking = false
local count = 0
local oldCount
local alreadyHit = { }
local char = players.LocalPlayer.Character
local resetTime = 2
--local CharacterData = game.Players.LocalPlayer.CharacterData

local animLength = 0.5 
local animLength2 = 1
local animator = char.Humanoid.Animator
local Animations = game.ReplicatedStorage
local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
	Sen = { },
	Sakuya = { }
}
local moveset: { Animation }? = MOVESET_ANIMATIONS["Mokou"]
if not moveset then
	error("Moveset not found!")
end
local punchAnimations: { AnimationTrack } = {}
for index: number, animation: Animation in moveset do
	punchAnimations[index] = animator:LoadAnimation(animation)
end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == punchInput then
		if attacking == true then 
			print("Already punching!")
		elseif attacking == false then
			count = count + 1
			currentTime = tick()
			print("M1 count is now "..count)
			punchAnimations[count].Priority = Enum.AnimationPriority.Action
			punchAnimations[count]:Play()
			char.M1Box.CanTouch = true
			attacking = true
			if count <= 3 then
				task.wait(animLength)
				char.M1Box.CanTouch = false
				attacking = false
			elseif count >= 4 then
				task.wait(animLength2)
				char.M1Box.CanTouch = false
				attacking = false
				count = 0
			end
		end
	end
end)

task.spawn(function()
	while true do
		task.wait(0.25)
		if count > 0 then
			if tick() - currentTime >= resetTime then
				count = 0
			end
		end
	end
end)

char.M1Box.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not table.find(alreadyHit, hit.Parent.Humanoid) then
			table.insert(alreadyHit, hit.Parent.Humanoid)
			punchEvent:FireServer(hit.Parent.Humanoid, count, LAST_PUNCH_KNOCKBACK, LAST_PUNCH_UPWARDS_KNOCKBACK)
			task.wait(animLength)
			table.remove(alreadyHit, table.find(alreadyHit, hit.Parent.Humanoid)) -- OH MY GOD WHY ISNT THIS BUILT INTO THE FUNCTION
		end
	end
end)

What did I do? Check where I index the moveset from MOVESET_ANIMATIONS. All I did was change “CharacterData.Moveset” to specifically “Mokou”. This means that the CharacterData or CharacterData.Moveset is invalid. Like people said above, you likely tried to use StringValue as an index instead of StringValue.Value. This is it, your whole script, almost unchanged. The animations work, (I got an animation from the toolbox), everything. The only thing that isn’t here is the Event firing since I wasn’t feeling like replicating the events hierarchy in your game, which is unnecessary, since the server part seems to be working fine.


The algorithm is correct:

Create a read-only dictionary that consists of MovesetName = Animation
Gets the moveset of the Player’s CharacterData
If that moveset isn’t in MOVESET_ANIMATIONS (so if it is nil) then error out
Initialize an array called punchAnimations to contain loaded AnimationTracks
Finally, iterate thru every animation that the moveset has and add it to the punchAnimations array.


I also don’t like to leave my jobs half done, so I made the knockback system work for you. Here is the fixed ServerScript and LocalScript:

LocalScript

local UIS = game:GetService("UserInputService")
local punchEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("PunchEvent")
local walkspeedChanger = game:GetService("ReplicatedStorage").Events:WaitForChild("WalkspeedChanger")
local punchInput = Enum.UserInputType.MouseButton1
local players = game:GetService("Players")
local attacking = false
local count = 0
local oldCount
local alreadyHit = { }
local char = players.LocalPlayer.Character
local resetTime = 2
local LAST_PUNCH_KNOCKBACK = 1700
local LAST_PUNCH_UPWARDS_KNOCKBACK = 1000
--local CharacterData = game.Players.LocalPlayer.CharacterData

local animLength = 0.5 
local animLength2 = 1
local animator = char.Humanoid.Animator
local Animations = game.ReplicatedStorage.Animations
local MOVESET_ANIMATIONS: { [string]: { Animation } } = table.freeze{
	Mokou = { Animations.Mokou.Punch1, Animations.Mokou.Punch2, Animations.Mokou.Punch3, Animations.Mokou.Punch4 },
	Sen = { },
	Sakuya = { }
}
local moveset: { Animation }? = MOVESET_ANIMATIONS["Mokou"]
if not moveset then
	error("Moveset not found!")
end
local punchAnimations: { AnimationTrack } = {}
for index: number, animation: Animation in moveset do
	punchAnimations[index] = animator:LoadAnimation(animation)
end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == punchInput then
		if attacking == true then 
		elseif attacking == false then
			count = count + 1
			currentTime = tick()
			punchAnimations[count].Priority = Enum.AnimationPriority.Action
			punchAnimations[count]:Play()
			char.M1Box.CanTouch = true
			attacking = true
			if count <= 3 then
				task.wait(animLength)
				char.M1Box.CanTouch = false
				attacking = false
			elseif count >= 4 then
				walkspeedChanger:FireServer(count, animLength2)
				task.wait(animLength2)
				char.M1Box.CanTouch = false
				attacking = false
				count = 0
			end
		end
	end
end)

task.spawn(function()
	while true do
		task.wait(0.25)
		if count > 0 then
			if tick() - currentTime >= resetTime then
				count = 0
			end
		end
	end
end)

char.M1Box.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not table.find(alreadyHit, hit.Parent.Humanoid) then
			table.insert(alreadyHit, hit.Parent.Humanoid)
			punchEvent:FireServer(hit.Parent.Humanoid, count, LAST_PUNCH_KNOCKBACK, LAST_PUNCH_UPWARDS_KNOCKBACK)
			task.wait(animLength)
			table.remove(alreadyHit, table.find(alreadyHit, hit.Parent.Humanoid)) -- OH MY GOD WHY ISNT THIS BUILT INTO THE FUNCTION
		end
	end
end)

Server Script

local punchEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("PunchEvent")
local WalkspeedChanger = game:GetService("ReplicatedStorage").Events:WaitForChild("WalkspeedChanger") --might be unneeded but i can't test that so here it is... sigh

punchEvent.OnServerEvent:Connect(function(plr: Player, targetHum: Humanoid, count: number, FORCE_MULTIPLIER: number, UP_FORCE: number)
	local plrChar = plr.Character
	local plrHrp: BasePart = plrChar:FindFirstChild("HumanoidRootPart")
	local targetChar = targetHum.Parent
	local targetHrp: BasePart = targetChar:FindFirstChild("HumanoidRootPart")

	if count == 1 or count == 2 then
		targetHum.Health -= 3
	elseif count == 3 then
		targetHum.Health -= 4
	elseif count == 4 then
		targetHum.Health -= 4
		
		local direction = (targetHrp.Position-plrHrp.Position).Unit
		local initForce = (direction * FORCE_MULTIPLIER)
		local finalForce = Vector3.new(initForce.X, 1, initForce.Z) * Vector3.new(1, UP_FORCE, 1)
		
		targetHrp:ApplyImpulse(finalForce)
		print(finalForce)
	elseif count >= 5 then
		print("how the hell")
	end
end)

WalkspeedChanger.OnServerEvent:Connect(function(plr, count, waitTime)
	if count == 4 then --double check (wont prevent exploiting anyways but whatever...)
		plr.Character.Humanoid.WalkSpeed = 0
		task.wait(waitTime + 0.3)
		plr.Character.Humanoid.WalkSpeed = 32
	end
end)

To get the direction of the knockback, you don’t need the lookVector: I simply just did

local initForce = (targetHrp.Position - plrHrp.Position).Unit

Vector3.Unit is simply a normalized copy of the Vector with a magnitude (that is, a distance between these 2 values), of 1, so it simply returns that same Vector3, but withouth a length, only a direction. It’s like saying: (X = 0.5, Y = 0, Z = 0.5) This is aiming half at the X value, half at the Z value and is not aiming upwards at all. That, when multiplied by a multiplier, gives the Vector3 positioned in the world in studs, which is going to be that multiplier amount, in that direction.

After that, I create a new Vector3 value called “finalForce”, which only exists to apply the upwards force.

local finalForce = Vector3.new(initForce.X, 1, initForce.Z) * Vector3.new(1, UP_FORCE, 1)

It creates a new Vector3 that has the X value of the initForce, same for Z value, but a Y value of 1: which means that it is pointing towards the Y value. I then multiply it by a Vector3 of X value 1, Z value 1, and Y value the UP_FORCE. In that equation, what I’m saying is: “Make it so the force now also, not only having the X and Z values, but also having the value of UP_FORCE in the Y axis, while maintaining the X and Z values of initForce.”

OBS: You have to include the FireHandler and RagdollSystem since I do not have access to these. You also need to fix the CharacterData.Moveset problem mentioned earlier. Also, in the .Touched event for the hitbox in the local script, if hit.Parent.Humanoid then
does not work, as you’re trying to get that Humanoid directly, and that gives an error. I changed it to if hit.Parent:FindFirstChild("Humanoid") then, which can then be evaluated if found or not found, since if not found, it returns nil instead of erroring.

I have included the forces in the LocalScript: You can tweak to your likings.


NOTE:

This code review and debugging was done at 2 AM. Please consider reading the full post as I worked hard for it :slight_smile:. I like to help other programmers simply because when I needed help, I didn’t have access to the forum due to not have read enough. Also, I always try to explain my rewritten code as best as I can, including explaining what was wrong and what wasn’t, and I’m open for questions, even if the script works. My goal here is to teach, not to distribute code.

Holy hell. Thank you so much. I was away from home for a few days and couldn’t read any responses.

I’m honestly astonished you went into such detail for this lol, but i’m very grateful !! ^^

No problem. I just love helping people, to the best of my extent.