So I’m making a sync system like in those dancing games on roblox.
So the system is suppose to sync the player’s animations with another person and if they choose a different dance the other player’s dance should also change.
Here’s the problem. I can’t get the other player to stop dancing and change their dancing animation.
Script:
game.ReplicatedStorage.SyncStart.OnClientEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if char:WaitForChild("Head"):FindFirstChild("ClickDetector") then return end
local syncClickDetector = Instance.new("ClickDetector")
syncClickDetector.Parent = char:WaitForChild("Head")
syncClickDetector.MaxActivationDistance = 100
syncClickDetector.MouseClick:Connect(function(plrWhoClicked)
if plrWhoClicked.UserId == player.UserId then
if syncFrame.Visible == true then
return
end
local animationPlayingChange
syncFrame.Selected.Text = "Selected: "..plr.Name
syncFrame.CurrentDance.Text = plr.Info.currentAnimationPlaying.Value
if syncFrame.CurrentDance.Text == "" then
syncFrame.CurrentDance.Text = "N/A"
end
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
animationPlayingChange = plr.Info.currentAnimationPlaying:GetPropertyChangedSignal("Value"):Connect(function()
syncFrame.CurrentDance.Text = plr.Info.currentAnimationPlaying.Value
if syncFrame.CurrentDance.Text == "" then
syncFrame.CurrentDance.Text = "N/A"
end
if syncFrame.Sync.Text == "UnSync" then
print(currentAnimationPlaying)
if currentAnimationPlaying then
currentAnimationPlaying:Stop()
currentAnimationPlaying = nil
end
print(currentAnimationPlaying)
for _, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
if check(v) then
currentAnimationPlaying = humanoid.Animator:LoadAnimation(v.Animation)
currentAnimationPlaying:Play()
currentAnimationPlaying.TimePosition = v.TimePosition
for _, a in pairs(AnimationModule.UnlockedAnimations) do
if a[2] == v.Animation.AnimationId then
game.ReplicatedStorage.AnimationEvent:FireServer(a[1])
end
end
end
end
end
end)
syncFrame.Visible = true
local closeConnection
local syncConnection
local sync = syncFrame.Sync
syncConnection = sync.MouseButton1Up:Connect(function()
if syncFrame.CurrentDance.Text == "N/A" then return end
if sync.Text == "Sync" then
if currentAnimationPlaying then
currentAnimationPlaying:Stop()
currentAnimationPlaying = nil
end
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
for _, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
if check(v) then
currentAnimationPlaying = humanoid.Animator:LoadAnimation(v.Animation)
currentAnimationPlaying:Play()
print(currentAnimationPlaying)
currentAnimationPlaying.TimePosition = v.TimePosition
for _, a in pairs(AnimationModule.UnlockedAnimations) do
if a[2] == v.Animation.AnimationId then
game.ReplicatedStorage.AnimationEvent:FireServer(a[1])
end
end
end
end
--[[
for _, animation in pairs(AnimationModule.UnlockedAnimations) do
if animation[1] == syncFrame.CurrentDance.Text then
local anim = Instance.new("Animation")
anim.AnimationId = animation[2]
currentAnimationPlaying = humanoid.Animator:LoadAnimation(anim)
currentAnimationPlaying:Play()
--currentAnimationPlaying.TimePosition =
print("Playing same animation")
end
end
--]]
sync.Text = "UnSync"
elseif sync.Text == "UnSync" then
print("Stop sync")
currentAnimationPlaying:Stop()
currentAnimationPlaying = nil
sync.Text = "Sync"
end
end)
closeConnection = syncFrame.X.MouseButton1Up:Connect(function()
syncFrame.Visible = false
sync.Text = "UnSync"
syncFrame.CurrentDance.Text = "N/A"
syncFrame.Selected.Text = ""
animationPlayingChange:Disconnect()
syncConnection:Disconnect()
closeConnection:Disconnect()
end)
end
end)
end)
Issue:
animationPlayingChange = plr.Info.currentAnimationPlaying:GetPropertyChangedSignal("Value"):Connect(function()
syncFrame.CurrentDance.Text = plr.Info.currentAnimationPlaying.Value
if syncFrame.CurrentDance.Text == "" then
syncFrame.CurrentDance.Text = "N/A"
end
if syncFrame.Sync.Text == "UnSync" then
print(currentAnimationPlaying)
if currentAnimationPlaying then
currentAnimationPlaying:Stop()
currentAnimationPlaying = nil
end
print(currentAnimationPlaying)
for _, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
if check(v) then
currentAnimationPlaying = humanoid.Animator:LoadAnimation(v.Animation)
currentAnimationPlaying:Play()
currentAnimationPlaying.TimePosition = v.TimePosition
for _, a in pairs(AnimationModule.UnlockedAnimations) do
if a[2] == v.Animation.AnimationId then
game.ReplicatedStorage.AnimationEvent:FireServer(a[1])
end
end
end
end
end
end)
humanoid is the other player
hum is the player
currentanimationtrack is the other player’s current animation track