Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- -- Animation States
- local currentAnim = "IDLE"
- local ANIMS = {
- IDLE = {
- leftArm = CFrame.new(-1.5, 0, 0),
- rightArm = CFrame.new(1.5, 0, 0),
- leftLeg = CFrame.new(-0.5, -2, 0),
- rightLeg = CFrame.new(0.5, -2, 0),
- head = CFrame.new(0, 1.5, 0)
- },
- SIT = {
- leftArm = CFrame.new(-1.5, 0, 0) * CFrame.Angles(0.2, 0, -0.1),
- rightArm = CFrame.new(1.5, 0, 0) * CFrame.Angles(0.2, 0, 0.1),
- leftLeg = CFrame.new(-0.5, -1.5, 0.5) * CFrame.Angles(math.rad(90), 0, 0),
- rightLeg = CFrame.new(0.5, -1.5, 0.5) * CFrame.Angles(math.rad(90), 0, 0),
- head = CFrame.new(0, 1.5, 0) * CFrame.Angles(-0.1, 0, 0)
- },
- DANCE = {
- leftArm = CFrame.new(-1.5, 0, 0) * CFrame.Angles(0, 0, math.rad(-45)),
- rightArm = CFrame.new(1.5, 0, 0) * CFrame.Angles(0, 0, math.rad(45)),
- leftLeg = CFrame.new(-0.5, -2, 0) * CFrame.Angles(0, 0, math.rad(-10)),
- rightLeg = CFrame.new(0.5, -2, 0) * CFrame.Angles(0, 0, math.rad(10)),
- head = CFrame.new(0, 1.5, 0) * CFrame.Angles(0, math.rad(30), 0)
- }
- }
- local function createGUI()
- local screenGui = Instance.new("ScreenGui")
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 150, 0, 200)
- frame.Position = UDim2.new(0.9, -150, 0.5, -100)
- frame.BackgroundColor3 = Color3.fromRGB(255, 192, 203)
- local buttons = {"Idle", "Sit", "Dance"}
- for i, name in ipairs(buttons) do
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.8, 0, 0, 40)
- button.Position = UDim2.new(0.1, 0, 0, i * 50 - 30)
- button.Text = name
- button.BackgroundColor3 = Color3.fromRGB(255, 105, 180)
- button.TextColor3 = Color3.new(1, 1, 1)
- button.Parent = frame
- button.MouseButton1Click:Connect(function()
- currentAnim = name:upper()
- end)
- end
- frame.Parent = screenGui
- screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
- end
- local function createCompanion(player)
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- local companion = Instance.new("Model")
- companion.Name = "Companion"
- local humanoid = Instance.new("Humanoid")
- humanoid.Parent = companion
- -- Create parts
- local head = Instance.new("Part")
- local torso = Instance.new("Part")
- local leftLeg = Instance.new("Part")
- local rightLeg = Instance.new("Part")
- local leftArm = Instance.new("Part")
- local rightArm = Instance.new("Part")
- head.Size = Vector3.new(1.2, 1.2, 1.2)
- head.BrickColor = BrickColor.new("White")
- head.Name = "Head"
- head.CanCollide = false
- torso.Size = Vector3.new(2, 2, 1)
- torso.BrickColor = BrickColor.new("Pink")
- torso.Name = "Torso"
- torso.CanCollide = false
- leftLeg.Size = Vector3.new(1, 2, 1)
- rightLeg.Size = Vector3.new(1, 2, 1)
- leftLeg.BrickColor = BrickColor.new("Navy blue")
- rightLeg.BrickColor = BrickColor.new("Navy blue")
- leftLeg.CanCollide = false
- rightLeg.CanCollide = false
- leftArm.Size = Vector3.new(1, 2, 1)
- rightArm.Size = Vector3.new(1, 2, 1)
- leftArm.BrickColor = BrickColor.new("White")
- rightArm.BrickColor = BrickColor.new("White")
- leftArm.CanCollide = false
- rightArm.CanCollide = false
- local parts = {head, torso, leftLeg, rightLeg, leftArm, rightArm}
- for _, part in ipairs(parts) do
- part.Parent = companion
- end
- -- Create welds
- local welds = {}
- welds.head = Instance.new("Weld")
- welds.head.Part0 = torso
- welds.head.Part1 = head
- welds.head.Parent = torso
- welds.leftLeg = Instance.new("Weld")
- welds.leftLeg.Part0 = torso
- welds.leftLeg.Part1 = leftLeg
- welds.leftLeg.Parent = torso
- welds.rightLeg = Instance.new("Weld")
- welds.rightLeg.Part0 = torso
- welds.rightLeg.Part1 = rightLeg
- welds.rightLeg.Parent = torso
- welds.leftArm = Instance.new("Weld")
- welds.leftArm.Part0 = torso
- welds.leftArm.Part1 = leftArm
- welds.leftArm.Parent = torso
- welds.rightArm = Instance.new("Weld")
- welds.rightArm.Part0 = torso
- welds.rightArm.Part1 = rightArm
- welds.rightArm.Parent = torso
- companion.PrimaryPart = torso
- local time = 0
- RunService.Heartbeat:Connect(function(deltaTime)
- time += deltaTime
- -- Apply current animation
- local targetAnim = ANIMS[currentAnim]
- for part, targetCF in pairs(targetAnim) do
- if currentAnim == "DANCE" then
- -- Add dancing motion
- targetCF = targetCF * CFrame.Angles(0, math.sin(time * 5) * 0.3, 0)
- end
- welds[part].C0 = welds[part].C0:Lerp(targetCF, 0.1)
- end
- -- Update position
- if humanoidRootPart then
- companion:SetPrimaryPartCFrame(humanoidRootPart.CFrame * CFrame.new(2.5, 0, 0))
- end
- end)
- companion.Parent = workspace
- return companion
- end
- local function init()
- createGUI()
- local player = Players.LocalPlayer
- player.CharacterAdded:Connect(function()
- task.wait(1)
- createCompanion(player)
- end)
- if player.Character then
- createCompanion(player)
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement