So I am trying to fire a remote event when the projectile hits the enemy but it doesn’t seem to fire.
Client:
local Debris = game:GetService("Debris")
local part = script.Parent
local ZombiesFolder = workspace:WaitForChild("ZombiesFolder")
local isHit = false
local despawnTime = 4
local function Damage(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
script.DamageTarget:FireServer(hit) -- not firing
part:Destroy()
end
end
part.Touched:Connect(function(hit)
if hit:IsDescendantOf(ZombiesFolder) and not isHit then
isHit = true
Damage(hit)
end
end)
Debris:AddItem(part, despawnTime)
Server:
local damage = 10
local function Damage(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
end
end
end
script.Parent.DamageTarget.OnServerEvent:Connect(function(player, hit)
print(hit) -- nothing
if hit then
Damage(hit)
end
end)
local function Shoot(target)
local result = PlayShootAnimation()
if result then
local newProjectile = Projectile:Clone()
newProjectile.CFrame = ShootPart.CFrame
local attachment = Instance.new("Attachment")
attachment.Parent = newProjectile
local LinearVelocity = Instance.new("LinearVelocity")
LinearVelocity.Attachment0 = attachment
LinearVelocity.MaxForce = math.huge
LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
LinearVelocity.VectorVelocity = ShootPart.CFrame.LookVector * projectileSpeed
LinearVelocity.Parent = newProjectile
newProjectile.Parent = ProjectilesFolder
newProjectile.Handler.Enabled = true -- enables the local script
end
end
RunService.Heartbeat:Connect(function()
local nearestTarget, nearestDistance = GetNearestZombieInRow()
if nearestTarget ~= nil and nearestDistance ~= nil then
if tick() - shootCurrentTime >= shootCooldown then
shootCurrentTime = tick()
Shoot(nearestTarget)
end
end
end)
Projectile handler: (client)
local Debris = game:GetService("Debris")
local part = script.Parent
local isHit = false
local despawnTime = 4
local function Damage(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
script.DamageTarget:FireServer(hit)
part:Destroy()
end
end
part.Touched:Connect(function(hit)
if hit:IsDescendantOf(ZombiesFolder) and not isHit then
isHit = true
Damage(hit)
end
end)
Debris:AddItem(part, despawnTime)
Server Handler: (server)
local damage = 10
local function Damage(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
end
end
end
script.Parent.DamageTarget.OnServerEvent:Connect(function(player, hit)
print(hit) -- nothing
if hit then
Damage(hit)
end
end)