Hello I'm making a tow truck. I want car hook and tow truck hook to weld on touch. When hooks weld I want them to stay in their position. When I tried my script car was inside truck.
COMMUNITY QUESTION
How can i script tow truck's hook?
2 answers
Just insert a weld and have an Touched event,
script.Parent.Touched:connect(function(car)
local w = Instance.new("Weld", script.Parent) --Insert a weld with the parent of script.Parent
w.Part0 = script.Parent
w.Part1 = car
end)
Make it look something like this. This isn't a request site though. This is just to get you started.
This is my very detailed version of LordDragonZord's answer. It's also a little more complete and complex.
names = {"Back Bumper"} -- Put whatever names of the parts you want the hook to hook to here.
hook = script.Parent -- Whatever you want to hook the car to here.
hook.Touched:connect(function(hit) -- Detects when the hook is touched and does something.
for i,name in pairs(names) do -- This will loop for every name there is and assign that name "name".
if hit.Name == name then -- Detects if the hit's name is one of the names in the "names" table.
local weld = Instance.new("Weld", hook) -- Create a weld in the hook.
weld.Part0 = hook -- Set the first part as the hook.
weld.Part1 = hit -- Set the seconds part to the touched part wich has one of the names you wanted.
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
