today I learned how to script a simple sword with sounds but in studio the dummy takes damage and the slash sound plays but in the real game when I click it does the animation but not the damage or the sound...
can anyone help me please? (here is the sword script below... :) )
Here is the Damage script (Script)
script.Parent.Handle.Touched:Connect(function(p)
if script.Parent.CanDamage.Value == true then --i have a bool value in the tool called "Can Damage" and if its true the sword does damage
script.Parent.CanDamage.Value = false --will autimaticly turn false for a debounce (so the person wont take a million hits per second!)
local ehum = p and p.Parent:FindFirstChild("Humanoid") or p.Parent.Parent:FindFirstChild("Humanoid") --this line allows the enemie to take damage even thogh they have a hat or not...
if ehum then --if the statment above is true then
ehum:TakeDamage(18) -- the humanoid or person hit by this should receive 18 damage
script.Parent.Handle.Sound:Play() -- Whoos! the slash should play (but currently... its not in the real game :( )
end
end
end)
and here is the actual sword script (Local Script)
local canattack = true
local an1 = false
--script.Parent.Equipped:Connect(function()
--local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
--local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
--
--idle:Play()
--end)
script.Parent.Activated:Connect(function()
--local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.secAttack)
if canattack == true then--and an1 == false then
attack:Play()
--idle:Stop()
canattack = false
wait(.7)
attack:Stop()
---idle:Play()
canattack = true
script.Parent.CanDamage.Value = true
an1 = true
-- elseif canattack == true and an1 == true then
-- attack2:Play()
-- --idle:Stop()
-- canattack = false
-- wait(1)
-- attack2:Stop() -- i tryed to make a second animation happen after the first but it was a fail...
-- ---idle:Play() -- so the script ends here...
-- canattack = true
-- script.Parent.CanDamage.Value = true
-- an1 = false
end
end)

7 comments
Hmm ok Animation:Play(0.1, 1,2) ?????
No, just try to publish your animation because that prevents: an exploiter to get it & it's more smooth, just publish it and use the function I gave you
ok so doing this will make the person take damage and the sound will play? in the server...?
ok ima script it now
yes, the damage would work and aswell as the animation but the sound you could try to use game:GetService("ContentProvider"):Preload to load the sound maybe it will work :thinking:
OMG IT WORKS THANK YOU SOOOOO MUCH! i may have more questions for swords in the future BUT THANK YOU so much! I will Accept the answer!!! :D
Parent argument to Instance.new is deprecated.