Help with scripting sword

Ok so my sword wont do any damage or swing or anything and my character is holding the sword in the middle.

local tool = script.Parent

local function onTouch(partOther)
	
	local humanOther = partOther.Parent:FindFirstChild("Humaniod")
	
	if not humanOther then return end
	
	if humanOther.Parent == tool then return end
	
	humanOther:TakeDamage(50)
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)
2 Likes

local humanOther = partOther.Parent:FindFirstChild(“Humanoid”)
You write “Humaniod”
Try that.

And I don’t know for the Hold Thing.

that still didn’t do anything its still in the middle and not moving

Try this: local humanOther = partOther:FindFirstChild(“Humanoid”)
And I don’t understand this part

thats like saying Parent.Parent.Parent

Can you screenshot the sword and explorer.

Okay, this might work. On the first line, type

“local tool = script.Parent.Parent.Sword”
And try to change “local functions” to functions.

Screenshot (6)

1 Like

I think that code doesn’t even work.

i might just hafto make a new one

Personally, I believe that it would be easier if you put the animations inside the tool instead of creating one.

Also, you may need to weld the sword if the character is holding it in the middle.

I think that this function does nothing?

I believe that the easiest way to script a sword is to look through YouTube tutorials or learning from free models :slight_smile:

partOther:FindFirstAncestorOfClass('Model'):FindFIrstChildOfClass('Humanoid')

Also, move the handle or use Tool Handle plugins to change the grip.

im sorry if im late but i managed to make it work

local tool = script.Parent
local handle = tool.Handle
local owner = tool.Parent
local debris = game:GetService("Debris")
local alreadyused = false
local alreadyhit = false
function onTouch(hit)

	if alreadyhit == false  then
		alreadyhit = true
	if not hit.Parent then return end

		if hit.Parent == tool then return end
		if hit.Parent.ClassName ~= "Humanoid" then
		hit.Parent.Humanoid:TakeDamage(50)
		end
		end
        end
function slash()
	if alreadyused == false then
		alreadyused = true
		handle.Touched:Connect(onTouch)
    local Anim = Instance.new("StringValue")
	Anim.Name = "toolanim"
	Anim.Value = "Slash"
	Anim.Parent = tool
		debris:AddItem(Anim,0.1) -- Now it doesnt make any lag.
		wait(0.5) --change this if u want to
		alreadyused = false
		alreadyhit = false
	end
end

tool.Activated:Connect(slash)