Touched event not going off

Hello, me and a friend are trying to make a tycoon from scratch to get practice scripting and the part where he brick goes to get destroyed is not happening for some reason. We tried making it print “h” when it hits but it does not do that, so I think that the event is not going off for some reason. We do not know why, and have tried many things to fix it. The script was working earlier but then we made a new model and copy and pasted the script and now it does not work.

destroying = script.Parent
givemoney = game.ServerStorage.moneytogive
destroying.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid == nil then
        hit:destroy()
        givemoney.Name = "moneytogive"
        givemoney.Value = givemoney.Value + 5
    end
end)

What is ‘destroying’? I cannot see any references to it.

“destroying” is the part that it touches to get destroyed.

I’d appreciate the full code.
Hard to tell what you’ve done wrong when I can’t see much.

Actually, you’re checking if humanoid doesn’t exist in order to give the money, etc.
Change it to > if humanoid then

What do you mean by “full code”
?

Do you need the code we used to make the bricks drop from the dropper?

^^^^
That is your issue. Right?

Is this your whole script? If it is you’ve never actually defined what ‘destroying’ is, unless you define it the script has no idea what you’re talking about. You need to add another line at the beginning of the script that defines what destroying is. Ex:

destroying = game.Workspace.Part -- This is just an example
1 Like

That’s to make sure it isn’t a person, so it doesn’t kill them.

You’re checking if humanoid is nil, if so: it will execute the code.

Whoops, formatted incorrectly, I fixed the whole script. Refresh to see.

Apologies.

Use a local variable, no need for a global one… Pls.
Also, no need for the :Destroy() method.

How would the part be destroyed then?

You’re destroying the actual part that’s hitting it, destroy the ‘destroying’? I assume that’s what you want?

Wait, do you want these lines of code

        hit:destroy()
        givemoney.Name = "moneytogive"
        givemoney.Value = givemoney.Value + 5

to run whenever a player touches destroying, or a part that isn’t a player tocuhes destroying?

It is a tycoon, and as a part goes down the conveyor, we want the part to be destroyed upon hitting the end block.

destroying:Destroy() is your solution.

“destroying” is the end block, and when a part reaches the end of it, it should get destroyed. Our issue is that it isn’t.

Actually I’m pretty sure he’s doing it right here, he wants to destroy the part that hits it, he doesn’t want to destroy the destroying part.

1 Like

What you are doing now is destroying whatever hits it. Not the part itself (destroying).