I have tried to look through multiple forum pages, and they all say roughly the same thing. Part:GetTouchingParts() should return all of the colliding parts. However, this is not working for me. I would say that for me it works around 10% of the time. Here is my function to check for collision:
function checkCollision(part) -- new
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
I am using connection to get around the problem of having a part which has CanCollide set to false, and trying to get the collision of that part.
And here is where I use the function (used when a spell is fired, until there are no more spells in the workspace).
game.Workspace.Spells.Slopigus.ChildAdded:Connect(function()
local damage
spells_ignis = game.Workspace.Spells.Ignis:GetChildren()
while #spells_ignis > 0 do
wait(0.15)
for i,v in pairs(spells_ignis) do
local collisionCheck = checkCollision(v)
if #collisionCheck > 0 then
for x,y in pairs(collisionCheck) do
for m=1,#playerParts,1 do
if y.Name == playerParts[m] then
local characterOfCollision = y.Parent
local nameOfCollision = characterOfCollision.Name -- Could be used for scoreboard updates
-- Deal appropriate damage to player
characterOfCollision.Humanoid:TakeDamage(damage) -- Damage is defined inside of the "Ignis" spell object
break
end
end
end
print("Collision")
v:Destroy()
else
game.ReplicatedStorage.Debug.Recieve:FireAllClients()
end
end
end
end)
I am not opposed to completely re-doing my script, but I would need to know what I am doing wrong, and what I should be doing.
All help is appreciated.
