No worries! I just thought it’d be helpful for testing.
I’ll also try to add some prints to see if I can find the issue too!
No worries! I just thought it’d be helpful for testing.
I’ll also try to add some prints to see if I can find the issue too!
I do suspect the issue might be due to the way the animation is fetched and loaded, so do try this LocalScipt instead:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local animation = script:WaitForChild("Animation")
local function dance(player)
if player.Character then
local animator = player.Character.Humanoid.Animator
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
animationTrack:Play()
end
end
local function onClientEvent(player1, player2)
dance(player1)
dance(player2)
end
remoteEvent.OnClientEvent:Connect(onClientEvent)
You’ll need to place the dance Animation Instance as a child of this LocalScript for it to work though
I’ll try it out!
One question I have though is if I need to insert an AssetID into AnimationID property beforehand? Or will it insert the AnimationID of the currently playing animation into the property when the prompt is triggered?
You can either insert the animation ID on the script itself, but I’d personally recommend setting it yourself in Studio in the properties tab, either or would work in the end so it’s up to personal preference
What if I had it so when the prompt was triggered, it sent the AssetID number of the current playing animation as an string and then it inserted the string into the property?
Like this:
Serverscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage.RemoteEvent
local function getAnimationID(animation)
if animation and animation:IsA("Animation") then
return animation.AnimationId
end
return nil
end
local function onTriggered(player1, player2)
local player2Character = player2.Character
if player2Character then
local humanoid = player2Character:FindFirstChild("Humanoid")
local animator = humanoid and humanoid:FindFirstChild("Animator")
local playingAnimations = animator and animator:GetPlayingAnimationTracks()
local currentAnimation = playingAnimations and playingAnimations[1]
local animationID = getAnimationID(currentAnimation.Animation)
remoteEvent:FireClient(player1, player2, animationID)
end
end
local function onCharacterAdded(character, player1)
local ownerPrompt = Instance.new("ProximityPrompt")
ownerPrompt.ActionText = "Join"
ownerPrompt.Name = "OwnerPrompt"
ownerPrompt.HoldDuration = 1
ownerPrompt.ObjectText = "Hold E to join dance!"
ownerPrompt.RequiresLineOfSight = false
ownerPrompt.Parent = character.PrimaryPart
ownerPrompt.Triggered:Connect(function(player2)
onTriggered(player1, player2)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(character)
onCharacterAdded(character, player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local animation = script:WaitForChild("Animation")
local function dance(player, animationID)
if player.Character then
local animator = player.Character.Humanoid.Animator
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
animationTrack:Play()
-- Set AnimationID
if animationID then
animationTrack.Animation = animationID
print(animationID)
end
end
end
local function onClientEvent(player1, player2, animationID)
dance(player1, animationID)
dance(player2, animationID)
end
remoteEvent.OnClientEvent:Connect(onClientEvent)
EDIT: Nevermind… those scripts don’t work
You’ll need to change the scripts like so:
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local assetId = "rbxassetid://" -- Change it to the ID of your dance animation
local remoteEvent = ReplicatedStorage.RemoteEvent
local function onTriggered(player1, player2)
remoteEvent:FireAllClients(player1, player2, assetId)
end
local function onCharacterAdded(character, player1)
local ownerPrompt = Instance.new("ProximityPrompt")
ownerPrompt.ActionText = "Join"
ownerPrompt.Name = "OwnerPrompt"
ownerPrompt.HoldDuration = 1 -- I added this because in the object text you wrote "Hold E"
ownerPrompt.ObjectText = "Hold E to join dance!"
ownerPrompt.RequiresLineOfSight = false
ownerPrompt.Parent = character.PrimaryPart
ownerPrompt.Triggered:Connect(function(player2)
onTriggered(player1, player2)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(character)
onCharacterAdded(character, player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Local:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function dance(player, assetId)
if player.Character then
local animator = player.Character.Humanoid.Animator
local animation = Instance.new("Animation")
animation.AnimationId = assetId
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
animationTrack:Play()
animation:Destroy()
end
end
local function onClientEvent(player1, player2, assetId)
dance(player1, assetId)
dance(player2, assetId)
end
remoteEvent.OnClientEvent:Connect(onClientEvent)
Thank you! But I guess one of the issues with setting the assetID beforehand is whether or not the player1 plays a different animation than the animation that’s within the AnimationID. I’d like it to be based on the animation that’s currently being played, not a pre-set animation.
Which player would you like to take priority (as in, who copies who): the player who triggered the prompt or the player who’s prompt got triggered?
Thanks for the reply! That’s not exactly what I’m trying to achieve, as I’ve already accomplished that part. I’m trying to make the animation’s of both player’s sync up— like this video, but using a proximity prompt instead of the mouse:
The player who triggers the prompt copies the player who’s prompt got triggered!
Here’s a video example of what I’d like to achieve, but using the proximity prompt instead of the mouse:
https://vimeo.com/903041322?share=copy
This should hopefully work:
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage.RemoteEvent
local function onTriggered(player1, player2)
remoteEvent:FireAllClients(player1, player2)
end
local function onCharacterAdded(character, player1)
local ownerPrompt = Instance.new("ProximityPrompt")
ownerPrompt.ActionText = "Join"
ownerPrompt.Name = "OwnerPrompt"
ownerPrompt.HoldDuration = 1 -- I added this because in the object text you wrote "Hold E"
ownerPrompt.ObjectText = "Hold E to join dance!"
ownerPrompt.RequiresLineOfSight = false
ownerPrompt.Parent = character.PrimaryPart
ownerPrompt.Triggered:Connect(function(player2)
onTriggered(player1, player2)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(character)
onCharacterAdded(character, player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Local:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function onClientEvent(player1, player2)
if player1.Character then
local track1 = player1.Character.Humanoid.Animator:GetPlayingAnimationTracks()[1]
if track1 and player2.Character then
local track2 = player2.Character.Humanoid.Animator:LoadAnimation(track1.Animation)
track2:Play(0, track1.WeightCurrent)
end
end
end
remoteEvent.OnClientEvent:Connect(onClientEvent)
Edit: @Auevi I edited the LocalScript because I think I found a way that should sync the animations too
YES!!! It works!!!
THANK YOU SO SO MUCH!!!
You have no idea how thankful I am for all of your help, you have made me incredibly happy!!!
Can I message you if I run into any future issues??
You can message me from time-to-time if you’d like, glad I could help you find the solution
YOU ARE THE BEST!!! Thank you so much again!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.