I am coding a fire ball but it should explode on direct contact with a dummy or a player but sometimes it the touched event doesn't run and other times it runs but after a delay of like 0.5 seconds. here is the code:
local damage = 40 local TweenService = game:GetService("TweenService") script.Parent.Touched:connect(function(h) if h.Parent:FindFirstChild("Humanoid") and script.Parent.Value.Value~=h.Parent.Name and script.Parent:FindFirstChild(h.Parent.Name) == nil then h.Parent.Humanoid:TakeDamage(damage) print("hit and damaged"..h.Parent.Name) local firsthit = Instance.new("StringValue") firsthit.Name = h.Parent.Name firsthit.Parent = script.Parent script.Parent.Anchored = true damage = 15 local tweeninfo = TweenInfo.new( 0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false ) local partprop = { Size = Vector3.new(10,10,10); Transparency = 1; } local tween = TweenService:Create(script.Parent,tweeninfo,partprop) tween:Play() script.Parent.ParticleEmitter.Enabled = false wait(0.5) for i,v in pairs(script.Parent:GetTouchingParts()) do if script.Parent.Value.Value ~= v.Parent.Name and v.Name ~= script.Parent.Value.Value and script.Parent:FindFirstChild(v.Parent.Name) == nil and v.Parent:FindFirstChild("Humanoid") ~= nil then v.Parent.Humanoid:TakeDamage(damage) local thing = Instance.new("StringValue") thing.Name = v.Parent.Name thing.Parent = script.Parent print("damaged"..v.Parent.Name) end end else print("The player hit himself") end end)
Delays happens like 90% all the time when using .Touched event, I'm here just to tell you the facts. If you need to know how to prevent this, search it up on the wiki about lag and performance.