Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Tizzel40 243 Moderation Voter
6 years ago

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

0
oh no the code is kinda jumbled up...sry... :( Tizzel40 243 — 6y
0
1. use code blocks; 2. :Stop(); 3. :Play() Fifkee 2017 — 6y
0
cant read soz CjayPlyz 643 — 6y
0
i would use userinputservice keydown is deprecated andrewcooke582 -52 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
So wjere do i put tjese 2 scripts Tizzel40 243 — 6y
Ad

Answer this question