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)

1 comment
Profane language is not permitted on our website. Please review our Community Guidelines https://scriptinghelpers.org/help/community-guidelines