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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)
0
yooo thanks a ton dude kamoojan 10 — 4y
0
No problem SimpleFlame 255 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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

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 SimpleFlame 255 — 4y

Answer this question