We use cookies on this site to enhance your user experience

Sep 06 2018, 12:05 PM PST

-- Used to give players items when tool hits cupcakes
local tool = script.Parent
local scoop = tool.Scoop

local backpack = tool.Parent
local player = backpack.Parent
local playerStats = player:FindFirstChild("leaderstats")
local playerItems = playerStats:FindFirstChild("Items")
local playerSpaces = playerStats:FindFirstChild("Spaces")

local function onTouch(partTouched)
	local canHarvest = partTouched.Parent:FindFirstChild("CanHarvest")
	if canHarvest then
		if canHarvest.Value == true and playerItems.Value < playerSpaces.Value then
			playerItems.Value = playerItems.Value + 1
			canHarvest.Value = false
			-- Reset partTouched, the harvested item
			partTouched.Transparency = 1 
			partTouched.CanCollide = false
			wait(5)
			-- Make the harvested item reappear and usable again
			canHarvest.Value = true
			partTouched.Transparency = 0 
			partTouched.CanCollide = true

		end
	end
end

scoop.Touched:Connect(onTouch)