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)
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.
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)
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.
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)
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.