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

How To Make Touch React Faster?

Asked by 9 years ago

I am creating a Throwing Weapon to My Friend, it's otherwise fine, but the "Touch" part of the Script reacts too slowly or doesn't react at all. It's supposed to weld the touched part with the throwing object, but it won't react or the part welds too late and it looks weird when it's at like 20 studs or more away the part what is supposed to be welded at. Yes, so it welds it, but not always, and that's why I asked this Question here. How to make "Touch" function of the script react faster? This script is copied to the throwing object:

script.Parent.Touched:connect(function(hit)
    local Bforce = script.Parent:FindFirstChild("BodyForce")
    if hit.ClassName == "Part" and hit.Parent ~= script.creator.Value and hit.Parent ~= script.sword.Value then
        if Bforce then
            Bforce:Destroy()
        end
        local Weld = Instance.new("Weld", hit)
        Weld.C1 = hit.CFrame:toObjectSpace(script.Parent.CFrame)
        Weld.Part0 = script.Parent
        Weld.Part1 = hit
        game.Debris:AddItem(script.Parent, 2)
    end
end)

Thanks,

Swaggy(Duckie)

0
Touched is a signal, It should be fired the instant you do that event. Maybe your place is lagging? alphawolvess 1784 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

The function fires the Touched event instantly when all the conditions have been met. We could test if the Touchedevent is firing by simply adding a print().

script.Parent.Touched:connect(function(hit)
    local Bforce = script.Parent:FindFirstChild("BodyForce")
print("Touched Has been Activated")-- I putted the print() above the if statement so it will still print even if the if statement is false.    
if hit.ClassName == "Part" and hit.Parent ~= script.creator.Value and hit.Parent ~= script.sword.Value then
print("Part has been found")--I added a second print() after the if statement to make sure the if statement is true. Since in this case if the if statement is false it won't print("Part has been found").         
if Bforce then
            Bforce:Destroy()
        end
        local Weld = Instance.new("Weld", hit)
        Weld.C1 = hit.CFrame:toObjectSpace(script.Parent.CFrame)
        Weld.Part0 = script.Parent
        Weld.Part1 = hit
        game.Debris:AddItem(script.Parent, 2)
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

As user is right, yet unfortunately there IS no legitimate way to make the touched event happen any faster.

Answer this question