Script for Sword

I have this script for a sword. Though it doesn’t work and most of the top part of the script is underlined in red and the last end is also. Not sure whats wrong.

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

local InputService = game:GetService(“UserInputService”)
local InputType = Enum.UserInputType

local animation = nil
local slashAnimation = nil

tool.Equipped:Connect(function()
	animation = Instance.new(“Animation”)
	animation.AnimationId = “rbxassetid://"7132227504”
	slashAnimation = humanoid:LoadAnimation(animation)
end)

tool.Unequipped:Connect(function()
	animation:Destroy()
	slashAnimation = nil
end)

local debounce = false
InputService.InputBegan:Connect(function(input, processed)
	if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
		if debounce == false then
			debounce = true

			slashAnimation:Play()
			local Connection
			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(35)
				if humanOther.Health <= 0 then
					player.leaderstats.Souls.Value =  player.leaderstats.Souls.Value + 1 
					humanOther.Parent:Destroy()
				end
			end

			Connection = tool:WaitForChild("Handle").Touched:Connect(onTouch)

			slashAnimation.Stopped:Wait() 
			debounce = false
			Connection:Disconnect()
			wait(.2)
			debounce = false

		end

	end
1 Like

The AnimationId for the equip animation has a quote in the middle of it.

2 Likes

Try this:

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local InputService = game:GetService("UserInputService")
local InputType = Enum.UserInputType

local animation = nil
local slashAnimation = nil

tool.Equipped:Connect(function()
	animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://7132227504"
	slashAnimation = humanoid:LoadAnimation(animation)
end)

tool.Unequipped:Connect(function()
	animation:Destroy()
	slashAnimation = nil
end)

local debounce = false
InputService.InputBegan:Connect(function(input, processed)
	if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
		if debounce == false then
			debounce = true

			slashAnimation:Play()
			local Connection
			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(35)
				if humanOther.Health <= 0 then
					player.leaderstats.Souls.Value =  player.leaderstats.Souls.Value + 1 
					humanOther.Parent:Destroy()
				end
			end

			Connection = tool:WaitForChild("Handle").Touched:Connect(onTouch)

			slashAnimation.Stopped:Wait() 
			debounce = false
			Connection:Disconnect()
			wait(.2)
			debounce = false

		end

	end
end)	 -- You forgot this :D



You did some silly mistakes with quotation marks and stuff, but the main error was that you forgot to put an “end)” at the very end of the code.

1 Like

Eyyy thanks bro


1 Like