Bu kodda checkifalive neden kullanılıyor? local ReplicatedStorage =…
- User
Bu kodda checkifalive neden kullanılıyor?
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local RunService = game:GetService("RunService") local Debris = game:GetService("Debris")
local Config = require(ReplicatedStorage:WaitForChild("ClickFarmConfig"))
local Tool = script.Parent local Handle = Tool:WaitForChild("Handle") local Hitbox = Handle:WaitForChild("HitBox") -- Var olan hitbox part'ı kullanacağız
-- Temel Veriler local Animations = { Idle = Handle:WaitForChild("Idle"), -- Idle animasyonu Handle içerisinde Click = Handle:WaitForChild("Click"), -- Click animasyonu Handle içerisinde } local Sounds = { Slash = Tool:WaitForChild("SwordSlash"), -- Kesme ses efekti Tool içerisinde Unsheath = Tool:WaitForChild("Unsheath") -- Kılıcı çıkarma ses efekti Tool içerisinde } local AttackCooldown = Config.Scythe.AttackCooldown -- Sadece attack cooldown'ı config'den alıyoruz
local ToolEquipped = false -- Kılıcın takılı olup olmadığını kontrol eden değişken local IsAttacking = false -- Kılıcın saldırı yapıp yapmadığını kontrol eden değişken local IdleTrack -- Idle animasyonu için animasyon track'i
-- RemoteEvent tanımlama local grassDestroyedEvent = ReplicatedStorage:WaitForChild("GrassDestroyedEvent")
Tool.Enabled = true
-- Hitbox çarpışma işlemini tanımlayan fonksiyon function HitboxTouched(hit) if hit and hit:IsA("BasePart") and hit.Name:match("FarmGrass") and IsAttacking then -- Çimen yerel olarak yok edilir hit:Destroy() -- RemoteEvent ile sunucuya çimenin yok edildiğini bildir grassDestroyedEvent:FireServer(hit) end end
-- Hitbox'a çarpışma dinleyicisi ekleriz Hitbox.Touched:Connect(HitboxTouched)
-- Oyuncunun ve karakterinin hayatta olup olmadığını kontrol eden fonksiyon function CheckIfAlive() return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false) end
-- Kılıç ile saldırı yapma fonksiyonu function Attack() IsAttacking = false -- Başlangıçta saldırı yapmıyor Sounds.Slash:Play()
if Humanoid then local Track = Humanoid:LoadAnimation(Animations.Click) Track:Play() -- Click animasyonunu çalıştırır end delay(0.1, function() IsAttacking = true delay(0.27, function() IsAttacking = false end) end) -- AttackCooldown süresi boyunca bekle wait(AttackCooldown)end
-- Kılıç etkinleştirildiğinde çağrılan fonksiyon function Activated() if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then return end Tool.Enabled = false Attack() Tool.Enabled = true end
-- Kılıç takıldığında çağrılan fonksiyon function Equipped() Character = Tool.Parent Player = Players:GetPlayerFromCharacter(Character) Humanoid = Character:FindFirstChildOfClass("Humanoid") Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart") if not CheckIfAlive() then return end ToolEquipped = true Sounds.Unsheath:Play()
- Assistant