Ad
Log in to vote
0

How can i play an animation from a script?

Asked by
nbkdn 2
12 days ago

I want to do an animation for Voidacity's Script builder (more exactly this one: http://web.roblox.com/games/843468296/Void-Script-Builder-Place-1) so i can press a key and it plays the animation. But every time I try to do that, it's just moving the character randomly. Can someone help me understand how that works? I know that a script made for hacking (Grab Knife) its using CFrame to animate. My attempt was this:

local player = game.Players.nbkdn
repeat wait() until player.Character.Humanoid --I know i have this useless thing but im new to scripting and this is the only way it worked for me.
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local c = humanoid.Parent
local la = c["Left Arm"]
local ra = c["Right Arm"]
local ll = c["Left Leg"]
local rl = c["Right Leg"]
local head = c.Head
local t = c.Torso

mouse.KeyDown:connect(function(key)
    if key == "e" then
        t.CFrame = CFrame.new(-0.032, -0.039, 0)
        la.CFrame = CFrame.Angles(0, 0, math.rad(-91.902))
        ra.CFrame = CFrame.Angles(0, 0, math.rad(91.616))
        wait(0.1)
        t.CFrame = CFrame.new(-0.032, 0.429, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(-6.818))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(9.969))
        head.CFrame = CFrame.Angles(math.rad(3.667), 0, 0)
        wait(0.1)
        t.CFrame = CFrame.new(0, 1.072, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(-16.215))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(16.043))
        la.CFrame = CFrame.new(-0.537, 0.071, 0) * CFrame.Angles(0, 0, math.rad(-97.575))
        ra.CFrame = CFrame.new(0.33, 0.023, 0) * CFrame.Angles(0, 0, math.rad(93.965))
        head.CFrame = CFrame.Angles(math.rad(14.324), 0, 0)
        wait(0.45)
        t.CFrame = CFrame.new(0, -0.156, 0) * CFrame.Angles(math.rad(-6.36), 0, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(11.86))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(-7.563))
        la.CFrame = CFrame.new(0.216, -0.029, 0) * CFrame.Angles(0, 0, math.rad(-92.189))
        ra.CFrame = CFrame.new(-0.013, -0.001, 0) * CFrame.Angles(0, 0, math.rad(90.184))
        head.CFrame = CFrame.Angles(math.rad(-16.501), 0, 0)
        wait(0.15)
        t.CFrame = CFrame.new(0, -0.985, 0.093) * CFrame.Angles(math.rad(-6.36), 0, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(26.413))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(-23.434))
        la.CFrame = CFrame.new(0.29, -0.032, 0) * CFrame.Angles(0, 0, math.rad(-95.455))
        ra.CFrame = CFrame.new(-0.215, -0.002, 0) * CFrame.Angles(0, 0, math.rad(92.876))
        head.CFrame = CFrame.Angles(math.rad(-24.351), 0, 0)
        wait(0.05)
        t.CFrame = CFrame.new(0, -0.064, 0.054) * CFrame.Angles(math.rad(-0.401), 0, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(6.245))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(-4.641))
        head.CFrame = CFrame.Angles(math.rad(-0.688), 0, 0)
        wait(0.05)
        t.CFrame = CFrame.new(0, -0.064, 0.054) * CFrame.Angles(math.rad(0.859), 0, 0)
        ll.CFrame = CFrame.Angles(0, 0, math.rad(-1.776))
        rl.CFrame = CFrame.Angles(0, 0, math.rad(2.063))
    end
end)
0
KeyDown() is deprecated, please use UserInputService instead. AswormeDorijan111 329 — 12d
0
i know but it still works, i have problems with the cframe part nbkdn 2 — 12d
0
Don't use it even if it 'works'. Deprecation implies it can be removed in the near future therefore breaking your game scripts using that code. xPolarium 693 — 12d

1 answer

Log in to vote
0
Answered by
HaveASip 243 Moderation Voter
12 days ago

Here is an example (Use localscript for this, in StarterGui)

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = Character.Humanoid
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then --checking if player inputed key from keyboard
        if input.KeyCode == Enum.KeyCode.E then --checking input key
            local Animation = Instance.new("Animation")
            Animation.Parent = Character
            Animation.AnimationId = "rbxassetid://00000000" -- here is your animation id
            local Track = humanoid:LoadAnimation(Animation)
            Track:Play()
            Track.Stopped:Wait() --firing when animation is finished playing
            Animation:Destroy() --destroying
        end
    end
end)


Ad

Answer this question