Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local SwordHitEvent = ReplicatedStorage:WaitForChild("SwordHitEvent")
- local function flashRed(model)
- -- สร้าง Highlight สีแดง
- local highlight = Instance.new("Highlight")
- highlight.Adornee = model
- highlight.FillColor = Color3.new(1, 0, 0)
- highlight.OutlineColor = Color3.new(1, 0, 0)
- highlight.FillTransparency = 0.5
- highlight.OutlineTransparency = 0
- highlight.Parent = model
- -- กระพริบ Highlight
- for k, i in highlight:GetChildren() do end -- No children, just placeholder
- for i = 1, 3 do
- highlight.Enabled = true
- task.wait(0.07)
- highlight.Enabled = false
- task.wait(0.07)
- end
- -- ลบ Highlight หลังจบ
- highlight:Destroy()
- end
- local function playDamageSound(player)
- -- Find the equipped tool in the player's character
- local character = player.Character
- if character then
- for k, child in character:GetChildren() do
- if child:IsA("Tool") then
- local handle = child:FindFirstChild("Handle")
- if handle then
- local sound = handle:FindFirstChild("DamageSound")
- if sound then
- sound:Play()
- end
- end
- end
- end
- end
- end
- local function knockback(model, hitPos, attackerPos)
- for k, part in model:GetChildren() do
- if part:IsA("BasePart") then
- local direction = (part.Position - attackerPos).Unit
- part.AssemblyLinearVelocity = direction * 50 -- 1 stud knockback
- end
- end
- end
- SwordHitEvent.OnServerEvent:Connect(function(player, enemyModel, damage, hitPos)
- local humanoid = enemyModel:FindFirstChildOfClass("Humanoid")
- if humanoid and humanoid.Health > 0 then
- humanoid:TakeDamage(damage)
- playDamageSound(player)
- knockback(enemyModel, hitPos, player.Character and player.Character:GetPivot().Position or hitPos)
- flashRed(enemyModel)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment