Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a more efficient way of detecting collisions?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

0
oh wait I can't read. Heck. roblox136393 32 — 4y
0
I don't have a great idea on how to fix this. roblox136393 32 — 4y
0
It's fine I think I found a solution elitekiller2342 87 — 4y
Ad

Answer this question