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

Touched Script Stops Working After A While?

Asked by 2 years ago

Hi! i have made a script which detects if a tool has touched a part, However, after a couple scans. The part no longer changes the text. Any work around for this? Any help is great, thanks in advance! Script:

local db = false
script.Parent.Touched:Connect(function(hit)
    if not db then
        db = true
    local h = hit.Parent.Name
    if h == "milk" then
            script.Parent.Parent.screen.SurfaceGui.Frame.TextLabel.Text = "Error, cannot purchase. Try again."
            wait(5)
            script.Parent.Parent.screen.SurfaceGui.Frame.TextLabel.Text = "Scan item >"
            db = false
       end
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local db = false
script.Parent.Touched:Connect(function(hit)
    if not db then
        db = true
    local h = hit.Parent;h=h and h.Name
    if h == "milk" then
            script.Parent.Parent.screen.SurfaceGui.Frame.TextLabel.Text = "Error, cannot purchase. Try again."
            wait(5)
            script.Parent.Parent.screen.SurfaceGui.Frame.TextLabel.Text = "Scan item >"

       end
 db = false
    end

end)
Ad

Answer this question