Hey developers! I am currently trying to create a dance system that supports syncing.
If you’re unaware of what this is, when a player syncs with another their “dances” are exactly the same (same dance, same time position) until they unsync. I’ve started to try to make this script, but I haven’t got very far:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AnimationsModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Animations"))
local EventsFolder = ReplicatedStorage:WaitForChild("Events").Animations
local Remotes = {
Sync = EventsFolder:WaitForChild("Sync");
Dance = EventsFolder:WaitForChild("Dance");
}
local Gamepasses = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Gamepasses"))
local SyncGroups = {} -- [Player.UserId] = {PlayersThatAreSynced}
local function PlayerAdded(Player)
SyncGroups[Player.UserId] = {}
end
for _, Player in pairs(Players:GetChildren()) do
PlayerAdded(Player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(Player)
SyncGroups[Player.UserId] = nil
for Id, _ in pairs(SyncGroups) do
local Found = table.find(SyncGroups[Id], Player)
if Found then
table.remove(SyncGroups[Id], Found)
end
end
end)
function Dance(Player, AnimationId)
local Character = Player.Character or Player.CharacterAdded:Wait()
local CharactersToAnimate = {Character}
local Focused = SyncGroups[Player.UserId]
for I, Player in pairs(Focused) do
if Player.Character then table.insert(CharactersToAnimate, Player.Character) end
end
for _, Character in pairs(CharactersToAnimate) do
-- ?!?!?!?!?
end
end
Remotes.Sync.OnServerEvent:Connect(function(Player, ToSyncWith)
end)
Remotes.Dance.OnServerEvent:Connect(function(Player, AnimationName)
local AnimationId = AnimationsModule[AnimationName]
if AnimationId then
Dance(Player, AnimationId)
end
end)
The main thing I am struggling with is the SyncGroups logic and the actual animating. Does anyone have any help to offer? It’s appreciated.