Materi Roblox Permainan Harvest

https://drive.google.com/file/d/1HcUO_oA9vxyLsertA6siLZmcykiVpFYW/view?usp=drive_link



Local Script pada Text HarvestCount

local player = game.Players.LocalPlayer

local textLabel = script.Parent


--Tunggu leaderstats muncul

player:WaitForChild("leaderstats")

local harvest = player.leaderstats:WaitForChild("Harvest")


--Update GUI saat nilai berubah

harvest.Changed:Connect(function(value)

textLabel.Text = "Harvest: " .. harvest.value

end)


--set awal

textLabel.Text = "Harvest: " .. harvest.Value


Script ke-1 untuk crop

local crop = script.Parent

local clickDetector = crop:WaitForChild("ClickDetector")


clickDetector.MouseClick:Connect(function(player)

--Buat nilai leadertstats kalau belum ada

local leaderstats = player:FindFirstChild("leaderstats")

if not leaderstats then

leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

end

--Buat nilai hasil panen

local harvest = leaderstats:FindFirstChild("Harvest")

if not harvest then

harvest = Instance.new("IntValue")

harvest.Name = "Harvest"

harvest.Value = 0

harvest.Parent = leaderstats

end

--Tambah hasil panen

harvest.Value += 1

end)

Script ke-2 untuk crop

local crop = script.Parent

local clickDetector = crop:WaitForChild("ClickDetector")


--Konfigurasi

local cooldown = 5 -- jeda waktu 5 detik

local maxHarvest = 5 -- maksimal panen sebelum tanaman hilang


--variabel

local canHarvest = true

local harvestCount = 0


clickDetector.MouseClick:Connect(function(player)

if not canHarvest then

return -- jika masih cooldown, abaikan

end

--tambah leaderstats harvest

local leaderstats = player:FindFirstChild("leaderstats")

if not leaderstats then

leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

end

local harvest = leaderstats:FindFirstChild("Harvest")

if not harvest then

harvest = Instance.new("IntValue")

harvest.Name = "Harvest"

harvest.Value = 0

harvest.Parent = leaderstats

end

--Tambah nilai panen

harvest.Value += 1

harvestCount += 1

print("Panen ke-" .. harvestCount .." dari tanaman ini")

--jika sudah mencapai batas maksimal

if harvestCount >= maxHarvest then

crop:Destroy()

return

end

--Mulai cooldown

canHarvest = false

clickDetector.MaxActivationDistance= 0 -- nonaktifkan klik sementara

wait(cooldown)

canHarvest = true

clickDetector.MaxActivationDistance = 32 -- aktifkan lagi (default 32)

end)



Boleh cek youtube ini

https://www.youtube.com/watch?v=aRBCESFfV2k&list=PL4CHT4GnImNjLJYg0P3j7xWSqSrMSjuC8&index=1



Komentar

Postingan populer dari blog ini

Script Roblox Studio (Character Free Falling)

Script Roblox Studio Kill Player, Lava Floor, Neon