Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My cloned part isn't cloning the TouchInterest which is vital to the script. How do I fix this?

So, in my workspace, I have a part that looks like this:

Part

  • Script
  • BodyVelocity

The script looks like this:

Boop = script.Parent
function sayhi()
	print("bruh")
end

Boop.Touched:Connect(sayhi)

When I run the game, the part looks like this:

Part

  • Script
  • TouchInterest
  • BodyVelocity

The original part works as intended, but when my gun clones the Part to shoot it out, it doesn't copy the touchinterest meaning that my script can't print "bruh" because it can't detect when it is touched.

How do I get the touchinterest to be cloned as well?

2 answers

✓ Accepted answer

If you want to clone a part I'd put it in ReplicatedStorage, that's what the storage is for. Also you can put the .Touched function inside of where your gun clones the part like so:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootingPart = ReplicatedStorage:WaitForChild("Part")

--// In your shooting function after you clone the part
local clone = shootingPart:Clone()
clone.Parent = workspace

clone.Touched:Connect(function()
	print("bruh")
end)

2 comments

0

yooo thanks a ton dude

0

No problem

or for the code above to be shorter since the "short cuts" are not needed

local shootingPart = game.ReplicatedStorage:WaitForChild("Part")

shootingPart:Clone().Parent = workspace

shootingPart.Touched:Connect(function()
    print("bruh")
end)

we dont need all those shortcuts so i narrowed it down to a shorter code, does the exact same thing though

1 comment

0

Huh? All kinds of things can go wrong when you code like that. It's so much easier to debug your code when you have set variables to narrow down the line the error came from. Edit: spelling

This discussion is preserved as it was. New answers, comments, and votes are closed.