I have worked on this for several days, and I have no idea what to do (also scattered the whole dev hub).
I have an animation that changes the default run animation when equipping a sword (The sword isn’t a tool, it’s a part that sticks to the players hand).
Problem: When I run with the default animation and change to my sword it still does the default animation, and not the new one.
local Event = game:GetService("ReplicatedStorage"):FindFirstChild("ChangeRunAnimation")
local SwordInHand = false
Event.OnServerEvent:Connect(function(Player)
if Player.character:FindFirstChild("Buster Sword") and not SwordInHand then
local humanoid = Player.character:FindFirstChild("Humanoid")
local runAnimation = "rbxassetid://12861501821"
local animateScript = Player.character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = runAnimation
SwordInHand = true
else if not Player.Character:FindFirstChild("Buster Sword") and SwordInHand then
local humanoid = Player.character:FindFirstChild("Humanoid")
local DefaultAnimation = "rbxassetid://507777826"
local animateScript = Player.character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = DefaultAnimation
SwordInHand = false
end
end
end)
Are you receiving any errors in the output?
Have you made sure that you placed the right animation Id’s for the run and default animations? And have you confirmed that the given code runs? There doesn’t seem to be any issue with this script, though, you do have the c lowercased for the player’s character.
There may be an issue with the LocalScript that fires the ChangeRunAnimation event, or possibly the Animate script.
try also setting the walk anim to the same as you run anim. If that doesn’t work try checking what animation priority the animation is because if it’s movement then that should work and it needs to be looped.
There is no error outputs, also the AnimateScript is just the default roblox animation folder directory. Also the local script that fires the event just fires this script when the user presses e (equips the weapon)
if Humanoid.MoveDirection.Magnitude > 0 then
wait(0.2)
for _, track in pairs(animationTracks) do
track:Stop()
end
local Animation = Instance.new("Animation", workspace.FX)
Animation.AnimationId = "rbxassetid://507777826" -- Default running animation Id
local animationTrack = Humanoid:LoadAnimation(Animation)
animationTrack:Play()
while animationTrack.IsPlaying do
if Humanoid.MoveDirection.Magnitude == 0 then
animationTrack:Stop()
end
wait()
end
end
This is the code I added to make the script work :3