Sword Script Wont Work

Hello! I’m trying to make a Sword, the issue is the script wont work ( Yes it is a local script and the child of the script is the tool )

-- Variables
local Debounce = false

local canHit = false

local randomSlash = 1

local idle

local Slash

local IdleSound
local SlashSound = script.Parent.Handle:WaitForChild("Slash")

local SlashAnim1 = script.Slash1Anim
local SlashAnim2 = script.Slash2Anim

-- Configure
local con = {
	trailEnabled = true;
	bloodEffects = true
}

-- Equip
script.Parent.Equipped:Connect(function()
	script.Parent.Handle.Equip:Play()
end)

-- Sword Slash
script.Parent.Activated:Connect(function()
	if not Debounce then
		Debounce = true
		if con.trailEnabled == true then
			script.Parent.Handle.Effect.Enabled = true
		end
		local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
		if not Slash then
			if randomSlash == 1 then
				Slash = humanoid:LoadAnimation(SlashAnim1)
				randomSlash = randomSlash + 1
			elseif randomSlash == 2 then
				Slash = humanoid:LoadAnimation(SlashAnim2)
				randomSlash = randomSlash - 1
			end
		end
		Slash:Play()
		wait(.2)
		SlashSound:Play()
		wait(.8)
		if Slash then
			Slash:Stop()
			Slash = nil
		end
		Debounce = false
	end
end)

-- Touch Function

script.Parent.Handle.Touched:Connect(function(hit)
	if Debounce then
		if not canHit then
			canHit = true
			local effect = script.Parent.Handle.Effect:Clone()
			if hit.Parent:FindFirstChild("Humanoid") then
				local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
				hit.Parent.Humanoid:TakeDamage(con.damage)
				if con.bloodEffects == true then
					effect.Parent = hit.Parent.HumanoidRootPart
					effect.Enabled = true
				end
			end
			wait(1)
			effect:Destroy()
			canHit = false
		end
	end
end)

Screenshot 2021-08-09 152650

5 Likes

What doesnt work specficially? You mean nothing works at all? Are there any errors in the output?

You never specified what’s wrong here.

1 Like

Like legit the whole script doesn’t work at all, I did clarify this one the post

@zCrxtix this is what I mean about the script

Since the whole script isn’t working I’ll just give you a new one. It’s a sever script btw.

local CanDamage = false
local Debounce = false
local Length = 0.3
local Cooldown = 0.2


script.Parent.Activated:Connect(function()
if Debounce == false then
Debounce = true
CanDamage = true
wait(Length)
CanDamage = false
wait(Cooldown)
Debounce = false
end
end)

local Damage = 15 --or whatever number you want
script.Parent.Handle.Touched:Connect(function(hit)
if CanDamage == true and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(Damage)
end
end)

This should be the whole script you can add the sounds and animations which should be easy.

1 Like
script.Parent.Activated:Connect(function()
	if not Debounce then
		Debounce = true
		if con.trailEnabled == true then
			script.Parent.Handle.Effect.Enabled = true
		end
		local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
		if not Slash then
			if randomSlash == 1 then
				Slash = humanoid:LoadAnimation(SlashAnim1)
				randomSlash = randomSlash + 1
			elseif randomSlash == 2 then
				Slash = humanoid:LoadAnimation(SlashAnim2)
				randomSlash = randomSlash - 1
			end
		end
		Slash:Play()
		wait(.2)
		SlashSound:Play()
		wait(.8)
		if Slash then
			Slash:Stop()
			Slash = nil
		end
	end
    Debounce = false
end)

All I did was move the debounce.

1 Like

I made 2 different type of animations and ticks and stuff, that was not easy for me to implement and I dont even know how I’m supposed to do it now

This didn’t do anything eathier.

So for the animations do:

local Character = script.Parent.Parent.Parent.Character --Not sure how many parents but you should be able to figure it out
local Animations = {
Slash1 = script:WaitForChild("Slash1Anim"),
Slash2 = script:WaitForChild("Slash2Anim"),
}
    local Move = 1
    script.Parent.Activated:Connect(function()
    if Debounce == false then
    Debounce = true
    CanDamage = true
    if Move == 1 then
    local Slash1 = Character.Humanoid:LoadAnimation(Animations.Slash1)
    Slash1:Play()
    Move = 2
    elseif Move == 2 then
    local Slash2 = Character.Humanoid:LoadAnimation(Animations.Slash2)
    Slash2:Play()
    Move = 1
    end
    wait(Length)
    CanDamage = false
    wait(Cooldown)
    Debounce = false
    end
    end)

Also if you have anything after like different sounds just put it after the animations.

1 Like

Have you checked if the script is running by putting a print() statement at line 1 of the script? I don’t doubt that it is, but it’s good to be sure

2 Likes

OK FINNALY ERRORS ARROSE

  07:28:46.174  Character is not a valid member of Workspace "Workspace"  -  Client - MainScript:87
  07:28:46.175  Stack Begin  -  Studio
  07:28:46.175  Script 'Workspace.NubblyFry.Sword.MainScript', Line 87  -  Studio - MainScript:87
  07:28:46.175  Stack End  -  Studio
  07:28:46.176  Equip is not a valid member of Part "Workspace.NubblyFry.Sword.Handle"  -  Client - MainScript:31
  07:28:46.176  Stack Begin  -  Studio
  07:28:46.176  Script 'Workspace.NubblyFry.Sword.MainScript', Line 31  -  Studio - MainScript:31
  07:28:46.177  Stack End  -  Studio
  07:28:58.027  Argument 1 missing or nil  -  Client - MainScript:72
  07:28:58.027  Stack Begin  -  Studio
  07:28:58.027  Script 'Workspace.NubblyFry.Sword.MainScript', Line 72  -  Studio - MainScript:72
  07:28:58.027  Stack End  -  Studio

Updated Script

-- Variables
local Debounce = false

local Length = 1

local Cooldown = 0.5

local canHit = false

local randomSlash = 1

local idle

local Slash

local IdleSound

local SlashSound = script.Parent.Handle:WaitForChild("SlashSound")

local SlashAnim1 = script.Slash1Anim
local SlashAnim2 = script.Slash2Anim

-- Configure
local con = {
	trailEnabled = true;
	bloodEffects = true
}

-- Equip
script.Parent.Equipped:Connect(function()
	script.Parent.Handle.Equip:Play()
end)

-- Sword Slash
script.Parent.Activated:Connect(function()
	if not Debounce then
		Debounce = true
		if con.trailEnabled == true then
			script.Parent.Handle.Effect.Enabled = true
		end
		local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
		if not Slash then
			if randomSlash == 1 then
				Slash = humanoid:LoadAnimation(SlashAnim1)
				randomSlash = randomSlash + 1
			elseif randomSlash == 2 then
				Slash = humanoid:LoadAnimation(SlashAnim2)
				randomSlash = randomSlash - 1
			end
		end
		Slash:Play()
		wait(.2)
		SlashSound:Play()
		wait(.8)
		if Slash then
			Slash:Stop()
			Slash = nil
		end
		Debounce = false
	end
end)

-- Touch Function

script.Parent.Handle.Touched:Connect(function(hit)
	if Debounce then
		if not canHit then
			canHit = true
			local effect = script.Parent.Handle.Effect:Clone()
			if hit.Parent:FindFirstChild("Humanoid") then
				local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
				hit.Parent.Humanoid:TakeDamage(con.damage)
				if con.bloodEffects == true then
					effect.Parent = hit.Parent.HumanoidRootPart
					effect.Enabled = true
				end
			end
			wait(1)
			effect:Destroy()
			canHit = false
		end
	end
end)

-- Slash

local Character = script.Parent.Parent.Parent.Character --Not sure how many parents but you should be able to figure it out
local Animations = {
	Slash1 = script:WaitForChild("Slash1Anim"),
	Slash2 = script:WaitForChild("Slash2Anim"),
}
local Move = 1
script.Parent.Activated:Connect(function()
	if Debounce == false then
		Debounce = true
		canHit = true
		if Move == 1 then
			local Slash1 = Character.Humanoid:LoadAnimation(Animations.Slash1)
			Slash1:Play()
			Move = 2
		elseif Move == 2 then
			local Slash2 = Character.Humanoid:LoadAnimation(Animations.Slash2)
			Slash2:Play()
			Move = 1
		end
		wait(Length)
		canHit = false
		wait(Cooldown)
		Debounce = false
	end
end)

Uhm you can just do

local Character  = game.Players.LocalPlayer.Character--Not sure how many parents but you should be able to figure it out

If I’m not mistaken.

Is that supposed to play an animation? .Equip doesn’t exits where you are directing the script to.

This one is also makind an error. Where does con.damage come from?

2 Likes
local con = {
	trailEnabled = true;
	bloodEffects = true
	damage = math.random(25,30,40)
}

Its supposed to play a sound, Forgot I renamed it.

1 Like

This is a normal script not a local script so that wouldn’t work.

Also I said experiment with the character I will help you so first keep doing .Parent after script until you find the sword’s name. Then if you keep going find StarterPack instead of writing StarterPack write Character.