Touched event is not firing

is the code in cash part because you have to make it so if the script parent is touched it would detect the part and other stuff, also replace FindFirstChild with FindFirstChildOfClass.

The code is in cash part. 123 133232

then make it so the local cash = script.Parent

Nothing changed too. (3O characters are so cool)

Then it’s supposed to work if you just detect the touch for the script’s parent. The cash parts are cloned and so will the script.

Hold on, First off, I will mention all the problems:

  • You need different methods of collecting "Hit’
  • You need a different script method.

Here’s how you accomplish this:

local part = script.Parent

part.Touched:Connect(function(hit)
    local h = hit
    if h then
       local FindHumanoid = h.Parent:FindFirstChild("Humanoid")
       if FindHumanoid then
          print("Found Humanoid")
      else
          warn("It's not a humanoid.")
       end
    end
end)

This is just an example, this is a method to collect the “hit” detection of a player. This can hopefully help accomplish what you wanted.

But : This will also not work, put the script in workspace and make a loop, inside of this loop try to find the part in workspace, if it’s found, then the function is found while the game is scanning the script. Here’s a example:

(Make sure it’s a script)

game.Players.PlayerAdded:Connect(function(player)
    while true do
       wait(0.5) -- put wait instead of task.wait() so the game can scan other parts of the script.
       local Find = game.Workspace:FindFirstChild("CashFolder")
       if Find and Find:IsA("BasePart") then
          Find.Touched:Connect(function(hit)
             -- Then use the rest of the collect touch method.
          end
       end
    end
end)

Now, Things to throw in you’re trash:

Terrible example, He just started coding.

Messy script, teaching him how to make his script’s messy, Plus does not work.

And now the rest of the comments:

There just terrible example’s. They don’t know what they are doing, throw all of those comments in the trash.

Anyways, if you have any questions, Ask me.

Things that you need to know:

  • It needs’ to be a script.
  • It needs to be in workspace.
  • Ask questions if there is problems.

Now here, you’re wrong. The script I provided him works, it’s simple: Once a child is added into the folder, the event is connected to that child. The .Touched event will work for all cash parts except those that were added before the server started running. So here’s an improved one, I should have thought of that:

local FolderOfCashParts = -- reference here

for _, CashPart in ipairs(FolderOfCashParts:GetChildren()) do
    CashPart.Touched:Connect(function(hit)

    end)
end
FolderOfCashParts.ChildAdded:Connect(function(child)
    child.Touched:Connect(function(hit)

    end)
end)

I do agree though that @pumpkyrofl 's code is messy. And this is not me come backing.

Now the script that you just now provided, is not a quite professional solution. You’re looping through every .5 seconds. This is what happens:

The .Touched event fires way more times than it should. Ideally it should fire 5-10 times (keep in mind the inaccuracy of the event) but here it fires over 100 times because you connect the event to the part every .5 seconds.

Detecting when the cash part is added into the folder and then connecting the event to that cash part is a way better solution performance and functionality wise.

@TheRealWerinq said that the script is located under the cash part, so he’ll just have to do this because when the cash part is cloned, it’s children will also be cloned over to that cloned cash part:

local CashPart = script.Parent

CashPart.Touched:Connect(function(hit)

end)

Down to the points:

Both wrong. The script can be in ServerScriptStorage, not just Workspace. It doesn’t need to be a server script as well if @TheRealWerinq would have wanted it to detect the touch locally.

We’re making everything complicated for this beginner so what you should do is test and do some research before replying. The solutions I provided are working and are far more better than yours.

So in conclusion, just do this:

local CashPart = script.Parent

CashPart.Touched:Connect(function(hit)

end)

I myself would use CollectionService or store all the cash parts in a folder just to organize everything and keep it more simple. @TheRealWerinq

You dont know that, you have not even tested out my script?

He never said it did, even if it did, he would give you the solution?

You’re script does not even work.

It still most likely works.

That’s not bad? It’s not like it’s 0.0001.

Wrong, First off, It make’s it more provick if it’s a script, Second off, It does need to be in workspace, in order to make it loop better.

That wont work.

You dont need to get to the advanced services. Just use my script.

Its not working too… 1`212121212121

And also your not working.

code i wrote:

local valuetogive = 1

game.Players.PlayerAdded:Connect(function(plr)
	while true do
		wait(.1)
		local find = game.Workspace:FindFirstChild("CashFolder")
		if find and find:IsA("BasePart") then
			find.Touched:Connect(function(hit)
							local char = hit.Parent
			local player = game.Players:GetPlayerFromCharacter(char)
			if player then
				print("found a player")
				local ls = player.leaderstats
				local cash = ls.Cash
				cash.Value += valuetogive
			end
			end)
		end
	end
end)

And its also in workspace and it is a script.

change find into iffind, find is representing something else, as you can tell, it’s blue.

Make sure your cash parts are always gonna be stored in a folder, then connect the .ChildAdded event to the folder. Then once the child is added, connect the .Touched event to that child. Just use the script I provided. I’m not sure what to say about @Sea_KidTwelve since his script was horrible both performance and functionality wise and it did not even work according to @TheRealWerinq. Yes, mine did not work but it did work for me. There must be an issue on your side.

No result. (3O CHARACTERS OMGMGMGM)

Sorry if we cant help you, if nothing works:

  • Use ChatGPT (Not in a bad way, just to learn.)
  • Directly message a professional.

alright let me settle this up.

local cash = script.Parent
local checkforhum(child)
if child.Parent:FindFirstChildOfClass("Humanoid") then
return child.Parent
else
checkforhum(child.Parent)
end
repeat task.wait() until cash.Parent == "likethefoldernameorworkspace"
cash.Touched:Connect(function(hit)
local checkers = checkforhum(hit.Parent)
if checkers ~= nil then
local hitplr = game.Players:GetPlayerFromCharacter(checkers)
if hitplr ~= nil then
hitplr:FindFirstChild("leaderstats").Cash.Value += 1
script:Destroy()
end
end)

i have one question, where did you got the child variable?

Finally proved you guys right, please watch this video: Streamable
It is literally the same script I provided earlier and it works correctly. It is definitely something on yall’s side.

And to you, @pumpkyrofl, please do research before posting as you’re a beginner. You’re not entirely ready to answer questions if you’re a beginner so that’s why you need to try your script out before providing it. The script you just provided was really messy. Instead, you could’ve just done this:

local Folder = script.Parent:WaitForChild("Folder")

-- We do this because we have parts in the folder that were added before runtime.
for _, part in ipairs(Folder:GetChildren()) do
	part.Touched:Connect(function(hit)
		if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			print("Touched.")
		end
	end)
end

Folder.ChildAdded:Connect(function(child)
	child.Touched:Connect(function(hit)
		if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			print("Touched.")
		end
	end)
end)

(Same code from the video, btw)

Did i mentioned you guys that the cash part is stores in replicatedstorage? And when i click on an specific part, the cash part spawns in workspace. That means that the cash part is not pre-loaded.