Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why the touched event takes some time to occur?

Asked by
shokobata -15
6 years ago
Edited by M39a9am3R 6 years ago

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)
0
Profane language is not permitted on our website. Please review our Community Guidelines https://scriptinghelpers.org/help/community-guidelines M39a9am3R 3210 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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.

0
if i added fireserver() in an event will it work? shokobata -15 — 6y
0
if i added fireserver() in an event will it work? shokobata -15 — 6y
Ad

Answer this question