so basically i try to make add sword a animation but it’s just don’t run, it’s placed here
SwordScript:
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://3493431823"
local animTrack
local tool = script.Parent
local char
tool.Activated:Connect(function()
local char = tool.Parent
animTrack = char.Humanoid:LoadAnimation(animation)
animTrack:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(animTrack.Length)
if dmg then
dmg:Destroy()
end
end)
tool.Unequipped:Connect(function()
if animTrack then
animTrack:Stop()
end
end)
damage script:
local weapon = script.Parent
local dmg = 5
weapon.Touched:connect(function(part)
if part.Parent:findFirstChild("Humanoid") then
local humanoid = part.Parent:findFirstChild("Humanoid")
humanoid:TakeDamage(dmg)
script:Destroy()
end
end)
please help me, i have this bug a month already and i have no idea how to solve it, thanks in advance
It’d be nice if you did some prior debugging first, which there is no indication of. When a script doesn’t work, the first thing you should be doing is checking your console for an error and a stack trace, not posting here.
Does your script error in any way?
On a separate note, some comments on your code:
There’s no need to instance the animation at run time.
There’s no debounce for actions. You should include one.
You should use an internal value as a flag to activate damage rather than an external script.
What specifically isn’t working? Is it only the animation? Ensure that the rest of your code is running in the first place.
If the rest of your code is functional aside from the animation, then it’s most likely to do with the animation itself. The most common case of error is failing to use an appropriate animation priority. In this case, you’d probably want Action.
Check the animation priority with code or via the Animation Editor. To check the priority with code, add this before you call play:
print(animtrack.Priority)
If it’s Core, it’s getting overridden by default animations. Change the priority in an animation editor if so, update the animation and try again. You can also set it with code.
That’s the issue then. You uploaded an animation with a priority of Core.
Go back to your Animation Editor and find the load option. Select the animation you uploaded and make sure it loads. Then, find the priority option and set it to Action. Once that’s done, select Export (or whatever the upload option is) and overwrite the animation you last uploaded.
Different topic altogether, which I mentioned in my first post:
local debounce = false
Activated:Connect(function ()
if not debounce then
debounce = true
-- Swing code
-- Somewhere after the animation ends:
debounce = false
end
end)