OnTouched Event Not Working On Still Objects

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I am trying to make a script that shoots lightning out of the player’s hand at does damage to a humanoid.

  2. What is the issue? On moving humanoids such as the drolling zombie the ontouched event is firing while on things like still other players or dummies it is now.

  3. What solutions have you tried so far? I have tried changing the hitbox length the hit the different parts of the humanoid

My hitbox code:

			Hitbox.Touched:Connect(function(hit)
				if not hit.Parent:FindFirstChild("Humanoid") then return end
					if hit.Parent.Name ~= Character.Name then
						local NewCharacter = hit.Parent
						if Hitppl[Player.Name] then return end
						Hitppl[Character.Name] = true
						
						local Animation = Instance.new("Animation")
						Animation.AnimationId = "rbxassetid://5380859448"
						local LoadAnimation = NewCharacter.Humanoid:LoadAnimation(Animation)
						LoadAnimation:Play()
						
						local BodPos = Instance.new("BodyPosition")
						BodPos.MaxForce = Vector3.new(5000000, 5000000, 5000000)
						BodPos.P = 50000
						BodPos.Position = NewCharacter:FindFirstChild("HumanoidRootPart").Position
						BodPos.Parent = NewCharacter:FindFirstChild("HumanoidRootPart")
						NewCharacter:FindFirstChild("Humanoid"):TakeDamage(DAMAGE)
						wait(0.1)
						
						if hit.Parent:FindFirstChild("Humanoid") then
							game.Debris:AddItem(BodPos,.1)
						else
							game.Debris:AddItem(BodPos,.2)
						end
					end
						
			end)

Hello. I don’t seem to understand what Player and Character are for. Is this being ran from a LocalScript? You’re likely running into replication issues if so.

Additionally, it may be a good idea to have a verification check to see if NewCharacter actually is the character of a player, you can use Players:GetPlayerFromCharacter to verify this. If you want to verify that it simply has a humanoid attached to it, you can instead just check for NewCharacter:FindFirstChild("Humanoid")

Yeah… I’m pretty sure that this is intended functionality. Looking at the code closely, you might want to look into using Raycasting

Also, I apologize for being blind as a bat when I mentioned the Humanoid check. I didn’t realize you already had one :sweat_smile:

Thanks I didn’t think of using ray casting I’ll try that.

1 Like