✓ Accepted answer
Just created an example on how to do this, Here are my scripts:
Local Script (Inside a Handle Less Tool!)
local Tool = script.Parent
local RS = game:GetService("ReplicatedStorage")
local DD = RS:WaitForChild("DealDamage",30)
function HandleDamage(Target,Damage)
local DebugMessages = true
if(Target == nil) then if(DebugMessages) then warn("Error: Target is nil!") end return end
if(Target.Parent == nil) then if(DebugMessages) then warn("Error Target.Parent is nil!") end return end
local Humanoid = Target.Parent:FindFirstChild("Humanoid")
if(Humanoid ~= nil) then
if(Humanoid.Health > 0) then
if(string.lower(Target.Name) == "head") then
if(DebugMessages) then print("Dealing Damage[",Damage,"] to [",Target.Parent,"'s Head!]") end
DD:FireServer(Target.Parent, Damage*2)
else
if(DebugMessages) then print("Dealing Damage[",Damage,"] to [",Target.Parent,"]") end
DD:FireServer(Target.Parent, Damage)
end
else
else
if(DebugMessages) then warn("Error: Target Has no Humanoid! \n ignoring....") end
end
end
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
HandleDamage(Mouse.Target, 15)
end)
end)
Server Script:
local RS = game:GetService("ReplicatedStorage")
local DealDamageEvent = RS:WaitForChild("DealDamage",30)
local function onDealDamageEventTo(player, Target, Damage)
if(Target == nil) then return end
local Humanoid = Target:FindFirstChild("Humanoid")
if(Humanoid ~= nil) then
Humanoid:TakeDamage(Damage)
end
end
DealDamageEvent.OnServerEvent:Connect(onDealDamageEventTo)
Setup:
Create a remote Event inside ReplicatedStorage and Name the event as DealDamage
Create a blank Tool and disable the setting "Requires Handle" then create a Local script inside the tool then paste the above local script inside replacing the print("Hello World") text.
create a Normal/Sever script inside ServerScriptService and name it anything you like then paste the above server script inside replacing print("Hello World") as you did the local script.
add a Humanoid Npc or player to your game (this will be your target)
Checklist and workings:
1)You should have a Tool with the above local script inside your Game.StarterPack
you should have a RemoteEvent Named "DealDamage" inside Game.ReplicatedStorage
You should have a Server(Normal) Script inside Game.ServerScriptService
A target Humanoid
If you've checked all the above, and you have it exactly as I've explained then when you hit play and click on your target Npc/Player they should lose health, and you should have an output of text displaying what the script(s) are doing!
If you have any questions/problems then let me know here and ill get back to you a.s.a.p! :)