I'm a new scripter and as a way to learn Lua I'm making a game based on Plants VS Zombies where you choose a plant and place them on a plot. I have a Pea Shooter model in Replicated Storage with a detection brick that for now only simply prints something whenever it detects something colliding it. The original model works fine when in workspace, but whenever it's cloned, the detection script stops working! I've tried disabling the script then enabling the script whenever it's cloned but obviously that didn't work. I think it may be a problem with the cloning script being local.
When a plot is clicked, it clones the Pea Shooter model from Replicated Storage to Workspace. This is a local script inside the starter pack.
mouse.Button1Down:Connect(function()
target = mouse.Target
playerPlant = player.PlantSelected.Value --update
print("CLICK")
print(playerPlant)
if target.name == "plot" and target.Taken.Value == 0 then
if playerPlant == "Pea Shooter" then
cloneTower(playerPlant)
end
else
if target.Taken.Value == 1 then
print("sorry, thats taken")
end
end
end)
function cloneTower (towerName)
tower = game.ReplicatedStorage[towerName]:Clone()
tower.Parent = workspace.Towers
tower.PrimaryPart = tower.Part
tower:SetPrimaryPartCFrame(target.CFrame + Vector3.new(0,3,0))
currentCFrame = tower:GetPrimaryPartCFrame()
tower:SetPrimaryPartCFrame(currentCFrame * CFrame.Angles(math.rad(180), math.rad(180), math.rad(70)))
target.Taken.Value = 1
wait(0.5)
tower.Detection.DetectScript.Disabled = false
end
This is the detection script within the Pea Shooter model. This works fine with the original model in the workspace, but it doesn't work when cloned!!! It doesn't even run the print.
print("HI")
function onTouched(part)
print("TOUCH")
end
script.Parent.Touched:connect(onTouched)

3 comments
Yep i think the problem is it is a local script
He said it worked on his original model.
I mean the script he use to spawn is local which would not work