i want to add swing and hit sound to my weapon script and i dont know how tho. :(

heres the script

local tool = script.Parent

local canDamage = false

local Cooldown = false

local WaitTime: number = 0.3 --// anything

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")

	if not humanoid then return end

	if humanoid.Parent ~= tool.Parent and canDamage then 
		humanoid:TakeDamage(15)
	else
		return
	end

	canDamage = false
end

local function slash()
	if Cooldown then return end
	Cooldown = true

	local str = Instance.new("StringValue")

	str.Name = "e" --idk why i made it e, i just edited the script that i used for an old game
	str.Value = "Slash"
	str.Parent = tool

	canDamage = true

	wait(WaitTime)

	Cooldown = false
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

2 comments

0

also an equip if ya can

1

https://developer.roblox.com/en-us/api-reference/class/Sound note this and other situations using sound with script.