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

Trying to make a script that makes an object a child after it's being touched?

Asked by 6 years ago

So, I am trying to make a script that when a fish Touches the Fishing rod, it becomes a child of it, I tried this script, but it doesn't work... Since I dont really know how to script, I dont know how to make an object a child of another when touched... If you notice any mistakes please tell me, I gain experience from you guys!

                local fish = game.Workspace.Fish
                  local WoodenFishingRod = game.StarterPack.WoodenFishingRod

                  fish.Touched.WoodenFishingRod:Connect(function(touch)
                  if touch.Name == "Fish" then
                  fish = WoodenFishingRod
                    print("Fish Captured!")
                    end
           end)

1 answer

Log in to vote
1
Answered by 6 years ago

Hello, here is how I would do it.

fish = script.Parent --Gets fish

script.Parent.Touched:connect(function(hit) --Fires if fished touched
    if not hit:FindFirstChild("WoodenFishingRod") then return end --Checks touched by fishing rod
    fish.Parent = hit --sets fish parent to the fishing rod
end)

I hope this helps!

Ad

Answer this question