Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script bug that duplicates animation help please?

Hello guys i use this script every time for animating in my game to play animations but when there are 2 people in the server the animations play 2 times

Is there a way to fix that

Basically if there are two players in the server the animation plays two times

If Im alone it works normally

The Code:


	 Animation = Instance.new("Animation")
	Animation.Parent = game.Workspace
	Animation.AnimationId = "http://www.roblox.com/asset/?id=538445969" 
	local Player = game.Players.LocalPlayer
	local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
	for i, v in pairs(game.Players:GetChildren()) do--i think its because of the GetChildren but then how do i fix that?
	if key == "f" then
		local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
			AnimationTrack:Play()
	

			
           
		    
	end
	end
	end)

Please tell me what makes it duplicate :/

1 answer

✓ Accepted answer
NewAnimation = Instance.new("Animation")
NewAnimation.Parent = game.Players.LocalPlayer.Character.Humanoid
NewAnimation.AnimationId = "http://www.roblox.com/asset/?id=538445969" 
local Player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
 if key == "f" then
 	local AnimationTrack = Player.Character.Humanoid:LoadAnimation(NewAnimation)
	AnimationTrack:Play()
        end
end)


3 comments

0

Ok so what do i do to fix it?

0

I edited my answer so try that

0

Please give explanations on your answers, so that the OP can understand your answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.