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

Touched Event Delay, Help?

Asked by
Invisum -5
7 years ago

When the script runs in test-mode (client) it runs as expected. When the script runs in a game, the onTouch event proves to be very delayed from the time the rocket hits the object to the time it actually explodes. Here's the code that makes the rocket explode:

script.Parent.Sound:Play()
debounce = true

script.Parent.Touched:connect(function(part)

    if debounce == true then
    debounce = false
    local explosion = Instance.new("Explosion")
    explosion.Parent = game.Workspace
    script.Parent.Explosion.PlayOnRemove = true
    explosion.Position = script.Parent.CFrame * Vector3.new(0,0,-script.Parent.Size.Z/2)
    function ExplosionHit(part)
    if part:IsA("Part") and part.Anchored == false and part.Shape.Name == "Block" then -- you can also use just the objectvalue of the part
       part.CanCollide = false
    end
    end
    local creator = script.Parent:findFirstChild("creator")

    function tagHumanoid(humanoid, creator)
    -- tag does not need to expire iff all explosions lethal    
    if creator ~= nil then
        local new_tag = creator:clone()
        new_tag.Parent = humanoid
    end
end

function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then
            tag.Parent = nil
        end
    end
end


local humanoid = part.Parent:FindFirstChild("Humanoid")
tagHumanoid(humanoid, creator)
explosion.Hit:connect(ExplosionHit)
script.Parent:remove()

  end
end)


0
Read my bio. hiimgoodpack 2009 — 7y
0
Just lag, cannot do anything about it ;/ Nowaha 459 — 7y

Answer this question