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

Change Stand Animation when player moves? ( jjba game )

Asked by 2 years ago
print("ServerScriptActive")
local rp = game:GetService("ReplicatedStorage")
local summon = rp:WaitForChild("Summon")
local Debris = game:GetService("Debris")


local TweenService = game:GetService("TweenService")

summon.OnServerEvent:Connect(function(Player, isActive)
    local Character = Player.Character
    local Humanoid = Character.Humanoid
    local Humrp = Character.HumanoidRootPart
    if isActive then
        local Stand = script:WaitForChild("Stand"):Clone()

        for _, part in pairs(Stand:GetDescendants()) do
            if part:IsA("BasePart") then
                part.Transparency = 1
            end
        end

        Stand.Parent = Character
        Stand.PrimaryPart.CFrame = Humrp.CFrame
        local weld = Instance.new("ManualWeld")
        weld.Name = "Controller"
        weld.Part0 = Stand.PrimaryPart
        weld.Part1 = Humrp
        weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
        weld.Parent = weld.Part0

        local AnimControl = Stand:FindFirstChild("AnimControl")
        local standHumrp = Stand:FindFirstChild("HumanoidRootPart")

        local Idle = AnimControl:LoadAnimation(script.Idle)
        local MovingAnim = AnimControl:LoadAnimation(script.MovingAnim)

        if Humanoid.MoveDirection.Magnitude > 0 then
            MovingAnim:Play()
        else
            Idle:Play()
        end

        for _, part in pairs(Stand:GetDescendants()) do
            if part:IsA("BasePart") and part ~= standHumrp then
                local goal = {}
                goal.Transparency = 0
                local info = TweenInfo.new(.5)
                local tween = TweenService:Create(part,info,goal)
                tween:Play()
            end
        end
        local goal = {}
        goal.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
        goal.C1 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame * CFrame.new(-3,1,2))
        local info = TweenInfo.new(.5)
        local tween = TweenService:Create(weld,info,goal)
        tween:Play()
    else
        local Stand = Character:FindFirstChild("Stand")
        if Stand then
            local Controller = Stand.PrimaryPart:FindFirstChild("Controller")
            if Controller then
                local standHumrp = Stand:FindFirstChild("HumanoidRootPart")
                for _, part in pairs(Stand:GetDescendants()) do
                    if part:IsA("BasePart") and part ~= standHumrp then
                        local goal = {}
                        goal.Transparency = 1
                        local info = TweenInfo.new(.5)
                        local tween = TweenService:Create(part,info,goal)
                        tween:Play()
                    end
                end
                local goal = {}
                goal.C0 = Controller.Part0.CFrame:ToObjectSpace(Controller.Part1.CFrame)
                goal.C1 = Controller.Part0.CFrame:ToObjectSpace(Controller.Part1.CFrame * CFrame.new(0,0,0))
                local info = TweenInfo.new(.5)
                local tween = TweenService:Create(Controller,info,goal)
                tween:Play()
                tween.Completed:Connect(function()
                    Debris:AddItem(Stand,0.1)
                end)
            end

        end
    end
end)

Sorry for the big script but at the part where I'm setting the animation I want the stand to change animations when moving only. I think its because this is only called when I summon the stand but I'm not sure how I would go about changing the animation from a separate script

In a nutshell how would I change the animation of the stand from a different script but only when the player moves

Answer this question