Sword won't work

Hello everyone! For some reason, this sword won’t work, it doesn’t do any animations/attacks. I’m using the Roblox classic sword and it’s a 2D game.

Script:

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local sword = game:GetService("ReplicatedStorage").ClassicSword

    humanoid:EquipTool(sword)
end)

Thanks for reading!

2 Likes

You’re using the roblox classic sword? Did you possibly choose the wrong one…? Use the one that’s made by ROBLOX themselves. The others might be a virus.

1 Like

Nope it’s the one made by Roblox

Try just deleting the current sword and putting it back in from the toolbox. Also scan your game for viruses by using anti-virus plugins that are confirmed.

1 Like

Already did that when you gave me your last message

Any other things you think I should do?

Create a whole new game. Might work.

1 Like

Like copy and paste the whole game?

No, create a new game. Same concept of the previous game though.

1 Like

I don’t think that’ll be necessary. When I inserted your script into studio, an error popped up.

I honestly don’t think it has anything to do with your place, the script just needs some rewriting.

1 Like

Yeah, could be that. Errors are important while doing anything on roblox.

3 Likes

Well, that error is to be expected. It’s obvious that OP doesn’t have the script as a direct descendant of the workspace, rather a descendant of a part, which does have a Touched event.

2 Likes

you can try using other sword models, and deleting virusses in them with an antivirus

1 Like

I’m not 100% sure why, but the reason this is happening is because if you directly equip a tool that isn’t a descendant of the player’s backpack, it breaks the tool. If you first clone the sword, set it as a parent of the Player’s backpack, and then equip that clone, the tool will function properly.

For example:

local Players = game:GetService('Players')

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

	local humanoid = hit.Parent:WaitForChild("Humanoid")
	local backpack = player:WaitForChild('Backpack')
	
	local sword = game:GetService("ReplicatedStorage").ClassicSword:Clone()
	sword.Parent = backpack

	humanoid:EquipTool(sword)
end)