How to clone part and only make it visible to local player?

Hello! I’ve got a problem. I need to clone part from ReplicatedStorage to workspace, but it should be only visible and touchable by local player. When i clone it in local script, onTouch does not work.

What do you mean by ontouch? [char limit]

You mean the .Touched function?

So, i’ve got Script in my part:

local part = script.Parent
local EChanged = game:GetService("ReplicatedStorage").Events.EChanged
local MatValue = part.Value.Value

local function onTouch(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then
		local hitplayer = game.Players:GetPlayerFromCharacter(hit.Parent)
		local leaderstats = hitplayer:WaitForChild("leaderstats")
		local res = leaderstats:WaitForChild("BasicResources")
		local mult = leaderstats:WaitForChild("BasicResourcesMult").Value
		EChanged:FireClient(hitplayer)
		res.Value = res.Value + MatValue*mult
		part:Destroy()
	end 
end 

part.Touched:Connect(onTouch) 

If i put it on workspace, it works like a charm. But when i clone it in my local script it is obviously does not work. I can do it with server script, but the thing is that i need it to be visible only to local player.

Copy paste the code into a localScript and put it into StarterPlayer → StarterPlayerScripts

Why dont you setup the .Touched function where your also cloning the part?

Can I?

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
-- TRIBAL --
local TribeS = workspace.Tribal:WaitForChild("tribals") 
local TribeSpeed = leaderstats:WaitForChild("BasicResourcesSpeed").Value
local TribalMats = game:GetService("ReplicatedStorage").Mats.Tribal

while true do
    wait(TribeSpeed)
    local randomMat = TribalMats:GetChildren()[math.random(1, #TribalMats:GetChildren())]
    local newPart = randomMat:Clone()
    newPart.Parent = workspace.Tribal
	newPart.CFrame = TribeS.CFrame * CFrame.new(math.random(-17,17), 1, math.random(-17,17)) * CFrame.Angles(0,0,math.rad(90))
end

I don’t quite understand where can i put that here :<

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
-- TRIBAL --
local TribeS = workspace.Tribal:WaitForChild("tribals") 
local TribeSpeed = leaderstats:WaitForChild("BasicResourcesSpeed").Value
local TribalMats = game:GetService("ReplicatedStorage").Mats.Tribal

local function onTouch(hit) 
	-- logic
end 

while true do
   wait(TribeSpeed)
   local randomMat = TribalMats:GetChildren()[math.random(1, #TribalMats:GetChildren())]
   local newPart = randomMat:Clone()
   newPart.Touched:Connect(onTouch)
   newPart.Parent = workspace.Tribal
   newPart.CFrame = TribeS.CFrame * CFrame.new(math.random(-17,17), 1, math.random(-17,17)) * CFrame.Angles(0,0,math.rad(90))
end

cloning and Touched are in different scripts, but i understood. Gonna merge them. Thanks!