Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched Event not firing?

Asked by 5 years ago

Basically, im getting nothing at all when this part is touched...

local pipeNumber = 1


script.Parent.Touched:Connect(function(hit)
    local model = hit.Parent:FindFirstChild'Humanoid'
    if model then 
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        if plr:FindFirstChild("PipesPassed") then 
            local pipesPassed = plr:FindFirstChild("PipesPassed")
            if pipesPassed.Value > pipeNumber then 
                pipesPassed.Value = 1 
                local plrcoins = game:GetService("ReplicatedStorage"):WaitForChild("LockedBanks"):FindFirstChild(plr.Name)
                plrcoins.Value = plrcoins.Value + 1
                print("success")
            end
        end
    else
        print("error")
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

A few debugging tips, as well as code tips. When using FindFirstChild(), do it like FindFirstChild("Humanoid"). The way you have it looks bad, and might be the reason you have issues.

A way to see if your part is truly being touched is to put a print right after the event. print("Whatever you want") is one idea you could put. When I debug my code, I often end up adding several dozens of prints and remove them as needed.

Another reason the code might not be running, is that maybe model isn't a thing.

Ad

Answer this question