How i Can Sent what object has been hit with health value and how to send it to all clients?
Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = script.Parent
local ToolsInfo = require(game:GetService("ReplicatedStorage").Modules.ToolsInfo)
local updateHealthEvent = replicatedStorage.Remotes.UpdateBreakablesHealthValue
local updateHealthToClientEvent = replicatedStorage.Remotes.UpdateBreakablesHealthToClients
--Sounds
local Sounds = replicatedStorage.Components.Sounds
local DebounceDuration = 0.8
local random = Random.new()
--States of Tool
local debounce = false
local debouncetree = false
local swinging = false
local DebounceDuration = 0.8
--Loading Damage From Module Script
local ToolTreeDamage = ToolsInfo[tool.Name].TreeDamage
local ToolBarrelDamage = ToolsInfo[tool.Name].BarrelDamage
local ToolNodeDamage = ToolsInfo[tool.Name].NodeDamage
local IdleAnim = tool:WaitForChild("Idle")
AttackAnim = tool:WaitForChild("Attack")
local IdleAnimation = character.Humanoid:LoadAnimation(IdleAnim)
local AttackAnimation = character.Humanoid:LoadAnimation(AttackAnim)
--Idle Animation
tool.Unequipped:Connect(function()
IdleAnimation.Priority = Enum.AnimationPriority.Action
IdleAnimation.Looped = false
IdleAnimation:Stop()
end)
tool.Equipped:Connect(function()
IdleAnimation.Priority = Enum.AnimationPriority.Action
IdleAnimation.Looped = true
IdleAnimation:Play()
end)
tool.Activated:Connect(function()
if character and character.PrimaryPart then
if debounce == false then
debounce = true
IdleAnimation:Stop()
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
IdleAnimation:Stop()
local swing = humanoid.Animator:LoadAnimation(tool.Attack)
AttackAnimation.Priority = Enum.AnimationPriority.Action4
swing.Looped = false
swing:Play()
wait(0.5)
swinging = true
task.wait(DebounceDuration)
swing:Play()
swinging = false
debounce = false
end
end
end
end)
tool.Body.Touched:Connect(function(hit)
if hit.Parent.Parent.Name == "Breakables" then
if debouncetree == false and debounce == true then
local tree = hit.Parent
debouncetree = true
if tree.ObjectType.Value == "Barrel" then
local hitsound = Sounds.Object.Barrels.BarrelHit1
local barrelhitsoundclone = hitsound:Clone()
tree.Health.Value = math.max(tree.Health.Value - ToolBarrelDamage, 0)
barrelhitsoundclone.Parent = tree.PrimaryPart.SoundPlace
barrelhitsoundclone:Play()
wait(0.6)
barrelhitsoundclone:Destroy()
elseif tree.ObjectType.Value == "Tree" then
Sounds.Object.Tree.TreeHit1:Play()
tree.Health.Value = math.max(tree.Healh.Value - ToolTreeDamage, 0)
elseif tree.ObjectType.Value == "Node" then
Sounds.Object.Tree.TreeHit1:Play()
tree.Health.Value = math.max(tree.Healh.Value - ToolNodeDamage, 0)
end
local randomTable = {random:NextNumber(0.1, 0.5), random:NextNumber(-0.5, 0.5)}
local x = randomTable[math.random(1, 2)]
local z = math.random(1, 2)
if z == 1 then
z = x
else
z = -x
end
local treeTween = tweenService:Create(tree.PrimaryPart, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true), {CFrame = tree.PrimaryPart.CFrame * CFrame.Angles(math.rad(x * 10), 0, math.rad(z *10)) + Vector3.new(x, 0,z)})
treeTween:Play()
if tree.Health.Value == 0 then
for _, v in pairs(tree:GetChildren()) do
if v:IsA("BasePart") then
tweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
end
end
task.wait(0.5)
tree:Destroy()
end
task.wait(DebounceDuration)
debouncetree = false
end
end
end)