the enemy fire remote event to the client and the client moves the enemy and then another remote event to the server which does hit detection
server script
local model = script.Parent
local primary = model.PrimaryPart
local waterStream = model:FindFirstChild("waterStream")
local beam = waterStream.Beam
local remoteEvent = model:WaitForChild("RemoteEvent")
local followDuration = 3
local mercyTime = 0.1
local function GetPlayer()
return game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
end
remoteEvent.OnServerEvent:Connect(function(player)
local connection
connection = waterStream.Touched:Connect(function(hit)
if hit.Parent == player.Character then
hit.Parent.Humanoid.Health = 0
end
end)
task.wait(1.5)
connection:Disconnect()
end)
task.wait(2 + (10-2)* math.random())
while true do
task.wait(6)
local target = GetPlayer()
if target then
remoteEvent:FireClient(target, followDuration, mercyTime)
task.wait(followDuration+mercyTime)
end
end
local script
local model = script.Parent
local primary = model.PrimaryPart
local waterStream = model:WaitForChild("waterStream")
local beam = waterStream:WaitForChild("Beam")
local RemoteEvent = model:WaitForChild("RemoteEvent")
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
RemoteEvent.OnClientEvent:Connect(function(followDuration, mercyTime)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local HRP = humanoid.RootPart
local randomDirection
repeat
randomDirection = Vector3.new(math.random(-10, 10), 1, math.random(-10, 10)).Unit
until randomDirection.Magnitude > 0.1
local elapsed = 0
local connection
connection = runService.PreRender:Connect(function(dt)
elapsed += dt
local offset = 10
local targetPosition = HRP.Position
model:PivotTo(CFrame.lookAt(targetPosition + Vector3.new(randomDirection.X * offset,0,randomDirection.Z * offset), targetPosition) * CFrame.Angles(0, math.rad(90), 0))
if elapsed >= followDuration then
model:PivotTo(CFrame.lookAt(targetPosition + Vector3.new(randomDirection.X * offset,0,randomDirection.Z * offset), targetPosition) * CFrame.Angles(0, math.rad(90), 0))
connection:Disconnect()
task.wait(mercyTime)
RemoteEvent:FireServer()
beam.Transparency = NumberSequence.new(0)
task.wait(1.5)
beam.Transparency = NumberSequence.new(1)
return
end
end)
end)