Hello Guys! I am new to script. So can someone tell me how to make a script that damages another npc or player. The current script i am using is
local tool = script.Parent
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(20)
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)
i found this script on toolbox. the animation works but does 0 damage
local tool = script.Parent
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther.Health = humanOther.Health -20
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)
local tool = script.Parent
tool.Handle.Touched:Connect(function(v)
local plr = game:serviceâPlayersâ:GetPlayerFromCharacter(v.Parent)
if plr and plr.Character then
if plr.Character:FindFirstChildâHumanoidâ then
plr.Character:FindFirstChildâHumanoidâ:TakeDamage(10)
end
end
end)
tool.Activated:Connect(function()
local str=Instance.newâStringValueâ
str.Name=âToolAnimâ
str.Value=âSlashâ
Str.Parent=tool
end)
â [[try this lil bro , i have not scripted in months but this should works]]