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 10 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:

01script.Parent.Touched:connect(function(hit)
02    local Bforce = script.Parent:FindFirstChild("BodyForce")
03    if hit.ClassName == "Part" and hit.Parent ~= script.creator.Value and hit.Parent ~= script.sword.Value then
04        if Bforce then
05            Bforce:Destroy()
06        end
07        local Weld = Instance.new("Weld", hit)
08        Weld.C1 = hit.CFrame:toObjectSpace(script.Parent.CFrame)
09        Weld.Part0 = script.Parent
10        Weld.Part1 = hit
11        game.Debris:AddItem(script.Parent, 2)
12    end
13end)

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 — 10y

2 answers

Log in to vote
0
Answered by 10 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().

01script.Parent.Touched:connect(function(hit)
02    local Bforce = script.Parent:FindFirstChild("BodyForce")
03print("Touched Has been Activated")-- I putted the print() above the if statement so it will still print even if the if statement is false.   
04if hit.ClassName == "Part" and hit.Parent ~= script.creator.Value and hit.Parent ~= script.sword.Value then
05print("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").        
06if Bforce then
07            Bforce:Destroy()
08        end
09        local Weld = Instance.new("Weld", hit)
10        Weld.C1 = hit.CFrame:toObjectSpace(script.Parent.CFrame)
11        Weld.Part0 = script.Parent
12        Weld.Part1 = hit
13        game.Debris:AddItem(script.Parent, 2)
14    end
15end)
Ad
Log in to vote
0
Answered by 10 years ago

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

Answer this question