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

Animation emote happens when "e" key is pressed is not working?

this my script and its not working...

local plr = game.Players.LocalPlayer local mouse = plr:GetMouse()

mouse.KeyDown:Connect(function(Key) if Key == "e" then local animation = Instance.new("Animation",plr.character) animation.animationid = "rbxassetid://1580824405" animate = plr.Character:FindFirstChild('Humanoid'):LoadAnimation(animation) animate:play() end end)

mouse.KeyUp:Connect(function(Key) if Key == "e" then animate:stop() end end)

-Tizzel40

4 comments

0

oh no the code is kinda jumbled up...sry... :(

0
  1. use code blocks; 2. :Stop(); 3. :Play()
0

cant read soz

0

i would use userinputservice keydown is deprecated

1 answer

Use Code blocks and KeyDown is deprecated. Switch to InputBegan from UserInputService. I will add a RemoteEvent so the server can play the animation and other players can see it.

--LocalScript

local player = game:GetService("Players").LocalPlayer
local rep = game:GetService"ReplicatedStorage"
local inputService = game:GetService"UserInputService"

inputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        rep.PlayAnimation:FireServer(game.Workspace.Anims.Animation) 

        -- I put the animation in the Workspace in a Folder
        
    end
end)

inputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        rep.StopAnimation:FireServer(game.Workspace.Anims.Animation) 

        -- I put the animation in the Workspace in a Folder
        
    end
end)
--ServerScript, handle animation playing/stopping.

local rep = game:GetService"ReplicatedStorage"

rep.PlayAnimation.OnServerEvent:Connect(function(player, animation)
    animTrack = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
    animTrack:Play()
end)

rep.StopAnimation.OnServerEvent:Connect(function(player, animation)
    animTrack:Stop() -- It was declared global so no errors here
end)

1 comment

0

So wjere do i put tjese 2 scripts

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