hey , so recently i got a new member (finally :D),i’m not experienced Scripter already telling, and i have a lot of bugs going on in my game, i’m not sure if i can post all the bugs in one post , i’ll make separate post (or should i do it in one post?)
ok, so the first bug in my game (that i wanted to fix it so much) is animation bug
(in this GIF i’m just taking my sword out, pressing mouse [animation doesn’t plays] , but when putting it in , the animation plays)
my script:
local animations = {"3492887169"}
local tool = script.Parent
local enabled = true
local char
tool.Activated:connect(function()
if enabled then
enabled = false
local char = tool.Parent
local random = animations[math.random(1,#animations)]
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id="..random
local track = char.Humanoid:LoadAnimation(anim)
track:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(track.Length)
enabled = true
if dmg then
dmg:Destroy()
end
end
end)
(if needed here’s a picture where it placed)
so that’s all, if you guys can recommend me how to make my posting much cleaner, i’ll appreciate it , thanks in advance
local animations = {“3492887169”}
local tool = script.Parent
local enabled = true
local char
local anim
tool.Activated:connect(function()
if enabled then
enabled = false
local char = tool.Parent
local random = animations[math.random(1,#animations)]
anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id="..random
local track = char.Humanoid:LoadAnimation(anim)
track:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(track.Length)
enabled = true
if dmg then
dmg:Destroy()
end
end
end)
tool.Unequipped:Connect(function()
if anim ~= nil then
anim:Stop()
end
end)
That should stop the animation when you unequip it. As for your random script, it is fine because you are finding the random of 1 between 1 in a table, which is 1 This is for your unequipping problem.
Hey, I recently just gotten invited as a New Member too, like 3 minutes ago actually and I thought I would solve this problem for you. You see, the animation track has a property called IsPlaying. Basically if animTrack.IsPlaying then you would destroy it. Simple enough. I’ll implement into code.
local animation = Instance.new(“Animation”)
animation.AnimationId = ID
local animTrack
tool.Activated:Connect(function()
animTrack = humanoid:LoadAnimation(animation)
animTrack:Play()
end)
tool.Unequipped:Connect(function()
if animTrack then
if animTrack.IsPlaying then
animTrack:Stop()
end
—[[Tbh with you, I recommed
just destroying the animTrack after you
check if it exists instead of
checking if it’s playing.—]]
end
end)
That was just an example on how you would implement it. Hope it helps.
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://3492887169"
local animTrack
local tool = script.Parent
local char
tool.Activated:Connect(function()
local char = tool.Parent
animTrack = char.Humanoid:LoadAnimation(animation)
animTrack:Play()
local track = char.Humanoid:LoadAnimation(animation)
track:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(track.Length)
if dmg then
dmg:Destroy()
end
end)
tool.Unequipped:Connect(function()
if animTrack then
if animTrack.IsPlaying then
animTrack:Stop()
end
end
end)
i did something like this, it doesn’t gives me errors but it doesn’t works either
Well you already did. It was the if animTrack then statement. After that you want to do animTrack:Destroy(). So remove the part that check if animTrack.IsPlaying.
It is supposed to be track:Stop() and track is the one that is a local variable outside. You should call the animation outside of the activated and create it before, so that it can play when you want it to.
local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://3492887169”
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(track.Length)
if dmg then
dmg:Destroy()
end
end)
tool.Unequipped:Connect(function()
if animTrack then
animTrack:Stop()
end
end)
This should work.