How to make a Sword script?

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

1 Like

Try this

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)

1 Like

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]]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.