Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

i am using in pairs for a tools but it keeps on printing the first tool in my hot-bar how do i fix?

trying to get the tools from local player baclpack

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local plr = game.Players.LocalPlayer

    if (humanoid ~= nil) then   
 for d,tools in pairs(plr.Backpack:GetChildren()) do 

    local i = Instance.new("TextLabel")
    local find = plr.PlayerGui:FindFirstChild("pack")
    i.Parent = find.Back
    if tools:IsA("Tool") then   
        i.Text = tools.Name
        print(tools.Name)
        break

    end
end
    end
end)

4 comments

1

just remove the break as said in the comments of your previous post, i tested it myself and it doesnt have a problem

0

BUT IT DOSE IT TWO TIMES I ONLY WANT IT TO DO IT one time

0

wait sorry it was toched so my bad

0

looks like you found the problem already, your touch function will keep repeating

1 answer

✓ Accepted answer

If you add a debounce, you're problem may stop.


script.Parent.Touched:Connect(function(hit)
local debounce = false
if debounce == true then
return
else
debounce = true
local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local plr = game.Players.LocalPlayer

    if (humanoid ~= nil) then   
 for d,tools in pairs(plr.Backpack:GetChildren()) do 

    local i = Instance.new("TextLabel")
    local find = plr.PlayerGui:FindFirstChild("pack")
    i.Parent = find.Back
    if tools:IsA("Tool") then   
        i.Text = tools.Name
        print(tools.Name)
debounce = false

    end
end
    end
end

end)

Might work, Comment if does not work. Set this as your answer if it is <3

This discussion is preserved as it was. New answers, comments, and votes are closed.