For some reason, the touched event isn't working. I don't know why! Help!
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local tool = script.Parent local Handle = tool:WaitForChild("Handle") local debounce = true local m = player:GetMouse() local speed = 150 tool.Activated:connect(function() if debounce == true then debounce = false local sound = tool.Sound sound:Play() wait(.3) sound:Stop() local pos = tool.Handle; local endPos = m.Hit.p; local ball = Instance.new("Part", workspace) ball.Name = "Ball_" .. player.Name; ball.CanCollide = false; ball.Shape = "Ball"; ball.Size = Vector3.new(1, 1, 1); local ray = Ray.new(pos.CFrame.p, (endPos - pos.CFrame.p).unit * 300); local hit, position = workspace:FindPartOnRay(ray, player.Character); local distance = (position - pos.CFrame.p).magnitude; ball.CFrame = CFrame.new(position, pos.CFrame .p) * CFrame.new(0, 0, 1.5) * CFrame.new(0, 0, -distance); game.Debris:AddItem(ball, 1); local sT = 0; local bv = Instance.new("BodyVelocity", ball); bv.velocity = -ball.CFrame.lookVector * speed; wait(.4) debounce = true ball.Touched:connect(function(hit) if hit.Parent.Torso:FindFirstChild("Fire") then local fire = hit.Parent.Torso.Fire game:GetService("Debris"):AddItem(fire, .01) end end) end end)
ball.Touched:connect(function(hit) --Check to make sure what you hit still exists and if a Torso exists. if ((hit ~= nil) and (hit.Parent:findFirstChild("Torso"))) then if (hit.Parent.Torso:FindFirstChild("Fire")) then -- Check for fire. -- Remove the fire game:GetService("Debris"):AddItem(hit.Parent.Torso.Fire, .01) end end end)
Also, move the ball.Touched function after
ball.Size = Vector3.new(1, 1, 1);
So the touched event isn't created 0.4 seconds after the ball is created...