I have a very simple touch event set up with a projectile fired by the player that kills the player it hits. Quite simply:
p.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= char then
db = false -- Debounce
local hum = hit.Parent.Humanoid
hum:TakeDamage(25)
folder:Destroy() -- Where parts of projectile are stored*
wait()
db = true
end
end)
-- *Projectile uses linear interpolation to 'fluctuate' the projectile's movement rather than have it move in a straight line (imagine a bolt of lightning), and so uses multiple parts to move.
The issue I'm having is - I'm afraid - rather ambiguous. The touch event only fires occasionally, peculiarly it seems to fire the first few times and only work rarely after that.
I'm pretty sure there is nothing wrong with the touched event itself (I'm including it just in case I've overlooked something), and I'm inclined to believe it is relating to the use of linear interpolation to fluctuate the projectile's movement using multiple parts and an small offset.
Effectively the part's movement works like this:
for i = 0, distance, step do
local from = lastPos
local offset = Vector3.new(
math.random(-offset, offset),
math.random(-offset, offset),
math.random(-offset, offset)
)/10
local to = from+-(from-to).unit*step+offset
local p = spell:Clone()
p.Parent = folder
p.Size = Vector3.new(p.Size.x, p.Size.y, (from-to).magnitude)
p.CFrame = CFrame.new(from:Lerp(to, 0.5), to)
local p2 = innerSpell:Clone()
p2.Parent = folder
p2.Size = Vector3.new(p.Size.x, p.Size.y, (from-to).magnitude)
p2.CFrame = CFrame.new(from:Lerp(to, 0.5), to)
game.Debris:AddItem(p, 0.1)
game.Debris:AddItem(p2, 0.1)
game.Debris:AddItem(folder, 10)
lastPos = to
-- Followed by the touch event I provided above
I appreciate the issue is, as I said, rather ambiguous, but it is so peculiar to me I really don't know what else I can say about it. If there's any more information you'd be interested in don't hesitate to ask.
Any suggestions or thoughts are appreciated.
