I'm trying to make a fast paced class fighting game and I've come across a big problem. My script for detecting collision via Touched event isn't working properly. 90% of the time the collision never happens and the damage isn't taken. Here's my script
debounce1=weaponpart.Touched:connect(function(hit) if (hit.Parent~=rootPart.Parent and hit.Parent:FindFirstChild("Humanoid")~=nil and hit.Parent:FindFirstChild("ForceField")==nil) then --if (game.Players:FindFirstChild(hit.Parent.Name)~=nil and game.Players:FindFirstChild(hit.Parent.Name).Team~=game.Players:FindFirstChild(script.Parent.Parent.Name).Team) then hit.Parent.Humanoid.Health=hit.Parent.Humanoid.Health-120 debounce1:disconnect() --end end end) wait(0.3) debounce1:disconnect()
The idea is for the weapon to play an animation, and wait for collision. After 0.3 seconds it disconnects the event to prevent it from firing accidentally
I don't know why this works so poorly but I was wandering if there was a more efficient way of dealing with collisions. One idea was implementing Magnitude detection. But I'm not sure if I want to go down that route
I have an Idea, you can create a Touched script like this
script.Parent.Touched:Connect(function(block) if block ~= game.Workspace:FindFirstChild("Block name that you don't want effected") then (Add anything) end end)
I hope that this works for you, if it does not work then... Oof.