BLOXBUILDS
Discord
Back
OBBY

Finish Line + Reward

Paste as a Script inside the finish part. The first touch grants Cash and plays a short firework burst above the player.

-- Paste as a Script inside the finish part.

local Players = game:GetService("Players")

local REWARD = 100

local part = script.Parent
if not part or not part:IsA("BasePart") then
	return
end

local finished: { [Player]: boolean } = {}

local function getCash(player: Player): IntValue
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then
		leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
	end

	local cash = leaderstats:FindFirstChild("Cash")
	if not cash then
		cash = Instance.new("IntValue")
		cash.Name = "Cash"
		cash.Value = 0
		cash.Parent = leaderstats
	end

	return cash :: IntValue
end

local function multiplier(player: Player): number
	local upgrade = player:GetAttribute("UpgradeLevel") or 0
	local rebirths = player:GetAttribute("Rebirths") or 0
	return (1 + upgrade * 0.25) * (1 + rebirths)
end

local function firework(position: Vector3)
	for index = 1, 8 do
		local spark = Instance.new("Part")
		spark.Size = Vector3.new(0.4, 0.4, 0.4)
		spark.Color = Color3.fromHSV(index / 8, 0.8, 1)
		spark.Material = Enum.Material.Neon
		spark.CanCollide = false
		spark.Anchored = false
		spark.Position = position
		spark.AssemblyLinearVelocity = Vector3.new(math.random(-30, 30), math.random(30, 50), math.random(-30, 30))
		spark.Parent = workspace
		task.delay(1.2, function()
			spark:Destroy()
		end)
	end
end

part.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if not player or finished[player] then
		return
	end

	finished[player] = true
	local amount = math.floor(REWARD * multiplier(player))
	getCash(player).Value += amount

	local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
	if root then
		firework(root.Position + Vector3.new(0, 4, 0))
	end
end)

Players.PlayerRemoving:Connect(function(player)
	finished[player] = nil
end)