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)
The function
fires the Touched
event instantly when all the conditions have been met. We could test if the Touched
event 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)
As user is right, yet unfortunately there IS no legitimate way to make the touched event happen any faster.