How to make a .Touched event work on a part generated by a LocalScript

I’m trying to make it so whenever a player touches an object created by a LocalScript, a script runs. Since a .Touched event only runs on a Script, which can’t access stuff on the client, I’m at a dead end.
I tried asking ChatGPT but it didn’t really work out

--corn gen localscript
local RepStorage = game:GetService("ReplicatedStorage")
local cornamount = RepStorage:WaitForChild("cornamount")
local module = require(RepStorage:WaitForChild("ModuleScript"))
local dirt = game.Workspace.dirt
local corn = RepStorage:WaitForChild("corn")
local CornHarvestEvent = RepStorage:WaitForChild("CornHarvestEvent")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer

local function addcorn()
	local corn2 = corn:Clone()
	corn2.Parent = game.Workspace
	corn2.Transparency = 0

	local randomVal = math.random(1,2)

	if randomVal == 1 then
		local x = math.random(-37,37)
		local z = math.random(-37,37)

		corn2.Position = dirt.Position +, dirt.Size.Y, z)
	elseif randomVal == 2 then
		local x = math.random(-37,37)
		local z = math.random(-37,37)

		corn2.Position = dirt.Position -, -dirt.Size.Y, z)
	cornamount.Value = cornamount.Value + 1

while true do
	if cornamount.Value <= module.CornCap then

Let me know if you need any more details or whatever
Any help is appreciated!

You can script a script and parent it in the part as an alternative.

--i dont know what your script does but i don't see the touched event

-- example
local fakeEvent = fake.Touched:Connect(function(something)
-- what it will do if fake part is touched

-- you can disconnect the touched event later if you wish and destroy the clone too
1 Like

The reason I didn’t include the .Touched event was because I felt like it would’ve done nothing to contribute since anywhere I put it, it doesn’t work anyways

You could use coroutines.

1 Like

I tried, but I dont think it worked
I’ll see if I can do it again in case i messed up

Totally wrong, I scripted a simulator game and I used LocalScript for checking if player has touched the Rebirth part.

1 Like