So I have the below script which is supposed to iterate through various parts in a folder, and if one of the parts is touched by a Bandit, then it gives them the loot, and disables that part from being looted again for 1000 seconds. I am storing the debounce as an attribute in the part. This script is in game.Workspace, and the parts are stored in a folder named LootParts, also within game.Workspace.
local LootParts = workspace.LootParts:GetChildren()
local function giveloot(Touched,Part)
Part = workspace.LootParts[Part]
local db = Part:GetAttribute("db")
if db == false then --debounce check
Part:SetAttribute("db",true) --activate debounce
local check = Touched.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
if check ~= nil then --If a human is found, then
local user = game.Players:GetPlayerFromCharacter(Touched.Parent) --get player from touching human
local stats = user:findFirstChild("leaderstats") --Find moneyholder
if user.Team == game.Teams.Bandits then
if stats ~= nil then --If moneyholder exists then
-- Give money
wait(1000) --cooldown
Part:SetAttribute("db",false)
end
end
end
end
end
for _,Part in pairs(LootParts) do
Part.Touched:Connect(giveloot(Part.Name))
end

1 comment
Connect is a method just like all others. It takes in a Callback function. If you're calling it while passing through, the function will pass in whatever it returns. If you want to call the function and pass an argument, you'll have to wrap it in an anonymous function.