CollectScript

PHOTO EMBED

Wed Jul 14 2021 02:47:33 GMT+0000 (Coordinated Universal Time)

Saved by @DefNotTaterTot

local Players = game:GetService("Players")
local collectPart = script.Parent
local collectable = true
local collectValue = 1
local respawnTime = 10

collectPart.Touched:Connect(function(otherPart)
	local character = otherPart:FindFirstAncestorWhichIsA("Model")
	if not character then return end

	local player = Players:GetPlayerFromCharacter(character)
	if not player then return end
	
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then return end

	local collectItem = leaderstats:FindFirstChild("Gems")
	if not collectItem then return end
	
	if collectable then
		collectable = false
		
		collectItem.Value += collectValue

		collectPart.Transparency = 1
		wait(respawnTime)
		collectPart.Transparency = 0

		collectable = true
	end
end)
content_copyCOPY