So I wanna make a pose system, Pressing G once would start the animation, Example of a game doing it:(https://gyazo.com/161ee902e358873c2b9b62d535af79a9)
On pressing G again, animation stops. How would I do that?
(My current code)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.G
then runtrack:Play()
if Input.Keycode == Enum.KeyCode.G
-- what do I do next?
2 Likes
Just realized that it’s very confusing, sorry about that.
EDIT 1: Forgot you can edit your comments
Here, I just typed this up in studio, I hope this helps.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
local AlreadyPressed = false
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.G and AlreadyPressed == false then
AlreadyPressed = true
runtrack:Play()
if Input.KeyCode == Enum.KeyCode.G and AlreadyPressed == true then
AlreadyPressed = false
runtrack:Stop()
end
end
end
end)
It’s creating no errors, but the animation doesn’t load, and the music doesn’t play, as you can see by
game.Workspace.sdiosong:Play()
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5468006525"
local runtrack = Humanoid:LoadAnimation(run)
local AlreadyPressed = false
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.P and AlreadyPressed == false then
AlreadyPressed = true
runtrack:Play()
game.Workspace.sdiosong:Play()
if Input.KeyCode == Enum.KeyCode.P and AlreadyPressed == true then
AlreadyPressed = false
game.Workspace.sdiosong:Stop()
runtrack:Stop()
end
end
end
end)
1 Like
okay, try this now.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.P then
runtrack:Play()
game.Workspace.sdiosong:Play()
end
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(Input, gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.P then
game.Workspace.sdiosong:Stop()
runtrack:Stop()
end
end
end)
Instead of adding a check, I just realized that roblox already has a built in function for this. Hope this helped! 
4 Likes
It’s on holding the key, but it still works. Thanks