Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a more efficient way of detecting collisions?

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

1 answer

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.

3 comments

0

oh wait I can't read. Heck.

0

I don't have a great idea on how to fix this.

0

It's fine I think I found a solution

This discussion is preserved as it was. New answers, comments, and votes are closed.