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

Help with Animation Playing off of KeyCode in LocalScript?

I'm trying to make a script that when the player clicks "T" it not only starts an animation but it enables the particles that are already placed in the character and have been disabled. Scripts not working any help ?


``local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid") local Animation = Instance.new("Animation") Animation.AnimationdID = "rbxassetid:2866299208" local track = Humanoid:LoadAnimation(Animation)

local particle = Character:WaitForChild("LeftUpperArm"):WaitForChild("ParticleEmitter") local particle1 = Character:WaitForChild("RightLowerArm"):WaitForChild("ParticleEmitter") local particle2 = Character:WaitForChild("RightUpperLeg"):WaitForChild("ParticleEmitter") local particle3 = Character:WaitForChild("UpperTorso"):WaitForChild("ParticleEmitter")

UserInputService.InputBegan:Connect(function(input, proc) if not proc and input.KeyCode == Enum.KeyCode.T then particle.Enabled = true particle1.Enabled = true particle2.Enabled = true particle3.Enabled = true track:Play() wait(3) track:Stop() end end)``

2 comments

0

Sorry that it looks weird I don't know how to do the thing with the view source

0

click the lua logo icon when youre writing and some ~ will appear write isnide them

1 answer

✓ Accepted answer

Since you're not waiting for the Character it might be broken because of that. Or it is because you misspelled AnimationId at Animation.AnimationdID = "rbxassetid:2866299208". It could be because you misspelled the link "rbxassetid:2866299208", it should be "rbxassetid://2866299208".

Here's the fixed script:

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer 
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid") 
local Animation = Instance.new("Animation") 
Animation.AnimationId = "rbxassetid://2866299208" 
local track = Humanoid:LoadAnimation(Animation)

local particle = Character:WaitForChild("LeftUpperArm"):WaitForChild("ParticleEmitter") 
local particle1 = Character:WaitForChild("RightLowerArm"):WaitForChild("ParticleEmitter") 
local particle2 = Character:WaitForChild("RightUpperLeg"):WaitForChild("ParticleEmitter") 
local particle3 = Character:WaitForChild("UpperTorso"):WaitForChild("ParticleEmitter")


 
UserInputService.InputBegan:Connect(function(input, proc) 
	if not proc and input.KeyCode == Enum.KeyCode.T then 
		particle.Enabled = true 
		particle1.Enabled = true
		particle2.Enabled = true 
		particle3.Enabled = true 
		track:Play() 
		wait(3) 
		track:Stop()
	end 
end)

I don't know your intentions, but you also might want to disable the particles at the end of the animation.

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