So if anyone knows about MoCap or animations. Ive been wondering how could I possibly turn / make a animation /sync command. Sort of like dancing and syncing with others. I mainly have everything down, but is their a certain way of finding the persons dance/animation or AnimationTrack that they are in and then putting/setting it as the person that wants to sync with the other person. Also looking for /leavesync which stops the dance animation for the command player.
So here are the main ideas/scripts,
Concept Script for ScriptService /sync command :
local syncthing = "/sync ([%w_]+)" --this is a string pattern that should match any player username
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local subjectName = msg:match(syncthing)
if subjectName then
local subject = game.Players:FindFirstChild(subjectName)
if subject then
-- finds the animation of the subject player
-- does the animation on the command player
end
end
end)
end)
Concept for /leavesync -
local syncthing = "/sync ([%w_]+)" --this is a string pattern that should match any player username
local leavesync = "/leavesync" -- string for leaving the sync
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local subjectName = msg:match(syncthing) -- checking to see if it matches text
if subjectName then
local subject = game.Players:FindFirstChild(subjectName)
if subject then
-- finds the animation of the subject player
-- does the animation on the command player
end
end
local leaveName = msg:match(leavesync) -- checking to see if it matches text
if leaveName then
-- stop animation
end
end)
end)
Working Script For Animations :
-- Locals for the animations.
wait(1)
local frame=script.Parent
local user=game.Players.LocalPlayer
repeat wait() until user.Character local char=user.Character
local humanoid=char:WaitForChild("Humanoid")
local anim
-- Function for playing the animations.
function playanim(id)
if char~=nil and humanoid~=nil then
local id="rbxassetid://"..tostring(id)
local oldanim=char:FindFirstChild("LocalAnimation")
if anim~=nil then
anim:Stop()
end
if oldanim~=nil then
if oldanim.AnimationId==id then
oldanim:Destroy()
return
end
oldanim:Destroy()
end
local animation=Instance.new("Animation",char)
animation.Name="LocalAnimation"
animation.AnimationId=id
anim=humanoid:LoadAnimation(animation)
anim:Play()
end
end
-- This is where you add more of your buttons and dances.. Just copy and paste. Make sure to change the b's.
local b1=frame.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) end)
local b2=frame.Button2
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) end)
local b3=frame.Button3
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) end)
local b4=frame.Button4
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) end)
local b5=frame.Button5
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) end)
local b6=frame.Button6
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) end)
local b7=frame.Button7
b7.MouseButton1Down:connect(function() playanim(b7.AnimID.Value) end)
local b8=frame.Button8
b8.MouseButton1Down:connect(function() playanim(b8.AnimID.Value) end)
local b9=frame.Button9
b9.MouseButton1Down:connect(function() playanim(b9.AnimID.Value) end)
local b10=frame.Button10
b10.MouseButton1Down:connect(function() playanim(b10.AnimID.Value) end)
local b11=frame.Button11
b11.MouseButton1Down:connect(function() playanim(b11.AnimID.Value) end)
local b12=frame.Button12
b12.MouseButton1Down:connect(function() playanim(b12.AnimID.Value) end)
local b13=frame.Button13
b13.MouseButton1Down:connect(function() playanim(b13.AnimID.Value) end)
local b14=frame.Button14
b14.MouseButton1Down:connect(function() playanim(b14.AnimID.Value) end)
local b15=frame.Button15
b15.MouseButton1Down:connect(function() playanim(b15.AnimID.Value) end)
local b16=frame.Button16
b16.MouseButton1Down:connect(function() playanim(b16.AnimID.Value) end)
Everything works except the part where I haven’t implemented the syncing. Any help would be appreciated!
You can use Animator:GetPlayingAnimationTracks() to get an array of all the animation tracks the player has playing, then you can try loading a new animation with the id of the animation you got from that array, waiting until it loads, and then set the AnimationTrack.TimePosition of the newly loaded animation track to the TimePosition of the target’s AnimationTrack
local animationmodule = {}
local Services = {
game:GetService(“ReplicatedStorage”);
}
local AnimDance = {}
function StopAnim(Plr)
if AnimDance[Plr] then
AnimDance[Plr]:Stop()
AnimDance[Plr]:Destroy()
end
end
function GetAnimID(Plr,id)
local MyAnim = Plr:WaitForChild(“Animation”)
MyAnim:SetAttribute(“CurrentAnim”,id)
MyAnim.AnimationId = “rbxassetid://” … MyAnim:GetAttribute(“CurrentAnim”)
if MyAnim:GetAttribute("CurrentAnim",id) == 0 then
MyAnim.AnimationId = ""
end
end
function PlayAnim(Plr)
local MyAnim = Plr:WaitForChild(“Animation”)
local AnimTrack =Plr.Character:WaitForChild(“Humanoid”):LoadAnimation(MyAnim)
AnimTrack:Play()
AnimDance[Plr] = AnimTrack
end
function SpeedAnim(Plr,speed)
local MyAnim = Plr:WaitForChild(“Animation”)
MyAnim:SetAttribute(“SpeedAnim”,speed)
if AnimDance[Plr] then
AnimDance[Plr]:AdjustSpeed(MyAnim:GetAttribute(“SpeedAnim”))
end
end
if Player.Character and Player.Character:FindFirstChild("Humanoid") then
if Bool == true then
StopAnim(Player)
GetAnimID(Player,Id)
PlayAnim(Player)
SpeedAnim(Player,1)
end
else
StopAnim(Player)
GetAnimID(Player,0)
end
end)
Services[1]:WaitForChild(“AnimationControl”):WaitForChild(“AnimSpeed”).OnServerEvent:connect(function(Player,speed)
if Player.Character and Player.Character:FindFirstChild(“Humanoid”) then
SpeedAnim(Player,speed)
button animation + button more attribu name AnimID
for i,r in pairs(AllAnim:GetChildren()) do
for ii,rr in pairs(r:GetChildren())do
if r.Name == “perk1” then
if rr:IsA(“TextButton”) then
rr.MouseButton1Click:Connect(function()
if rr:GetAttribute(“AnimID”)~= LocalPlayer:WaitForChild(“Animation”):GetAttribute(“CurrentAnim”) then
game:GetService(“ReplicatedStorage”):WaitForChild(“AnimationControl”):WaitForChild(“AnimPlay”):FireServer(rr:GetAttribute(“AnimID”),true)
else
game:GetService(“ReplicatedStorage”):WaitForChild(“AnimationControl”):WaitForChild(“AnimPlay”):FireServer(rr:GetAttribute(“AnimID”),false)
end end) end end
button speed
for _,S in pairs(Speed:GetChildren()) do
if S.ClassName == “TextButton” then
S.MouseButton1Click:Connect(function()
Services[2]:WaitForChild(“AnimationControl”):WaitForChild(“AnimSpeed”):FireServer(S:GetAttribute(“Speed”))
end) end end
you dont fire server and server cant view your annimation
local b1=frame.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) end)
mine = is better
rr.MouseButton1Click:Connect(function()
if rr:GetAttribute(“AnimID”)~= LocalPlayer:WaitForChild(“Animation”):GetAttribute(“CurrentAnim”) then
game:GetService(“ReplicatedStorage”):WaitForChild(“AnimationControl”):WaitForChild(“AnimPlay”):FireServer(rr:GetAttribute(“AnimID”),true) – play annimation if ~ your old anim
else
game:GetService(“ReplicatedStorage”):WaitForChild(“AnimationControl”):WaitForChild(“AnimPlay”):FireServer(rr:GetAttribute(“AnimID”),false) – stop annimation if same your old anim
end end) end end
local Player = game:GetService(“Players”)
function sync(plr1,plr2)
if plr1:WaitForChild(“PlayerSyncW”).Value ~= “” and plr1:WaitForChild(“PlayerSyncW”).Value == plr2 and Player:FindFirstChild(plr2) ~= nil then
local humanoid = plr1.Character:WaitForChild(“Humanoid”)
local humanoid2 = Player:WaitForChild(plr2).Character:WaitForChild(“Humanoid”)
local animation2 = Player:WaitForChild(plr2):WaitForChild(“Animation”)
local AnimationTracks = humanoid2:WaitForChild(“Animator”):GetPlayingAnimationTracks()
local AnimationTracks1 = humanoid:GetPlayingAnimationTracks()
for _, n in pairs(AnimationTracks) do
for i, track in pairs (AnimationTracks1) do
track:Stop()
track:Destroy()
end
local danceAnimation = humanoid:WaitForChild("Animator"):LoadAnimation(n.Animation) -- requires an animation object
danceAnimation:Play()
danceAnimation:AdjustSpeed(n.Speed)
danceAnimation.TimePosition = n.TimePosition
end
end
end
while wait() do
local LocalPlayer = Player.LocalPlayer
local player2name = LocalPlayer:WaitForChild(“PlayerSyncW”).Value
if player2name ~= “” then
sync(LocalPlayer,player2name)