Collect with Tool

SeverScriptService

local currency = "Candy"


game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = plr


local gold = Instance.new("IntValue")

gold.Name = currency

gold.Parent = leaderstats

end)

Items Folder

local folder = script.Parent

local toolName = "Collector"

local currency = "Candy"


local function collectItem(obj, otherPart)

local player = game.Players:FindFirstChild(otherPart.Parent.Name)

if player then

if player.Character:FindFirstChild(toolName) then

local amount = obj.Amount.Value

obj:Destroy()

player.leaderstats[currency].Value += amount

end

end

end



for _, obj in pairs(folder:GetChildren()) do


if obj:IsA("BasePart") then

obj.Touched:Connect(function(otherPart)

collectItem(obj, otherPart)

end)

elseif obj:IsA("Model") and obj:FindFirstChild('Hit') then

obj.Hit.Touched:Connect(function(otherPart)

collectItem(obj, otherPart)

end)

end

end