Edit:
I’ve found that the issue is due to the Animation
object not having the name I assign it due to replication (the animation is loaded in a separate local script and named there). Therefore I have a couple of questions in relation to this:
- Is there a way to set animation names preemptively? I don’t want to have to load animations on the server, but it seems this is likely one way to solve the problem - load animations on the server, name them, and put them into replicated storage. Is all this necessary?
- The other option I have is to connect to an event for every
GetMarkerReachedSignal
that I have for every animation I am planning to use (there are a lot!). This seems like a really, really poor choice, especially scaling to multiple players where all these connections will also be created. It’s a dumb question, but is this even a viable option?
I’m moving forward with 1 as of now, but if there are any glaring issues feel free to reply.
Hi, I’m trying to make an event handler for props in my game. It runs based on GetMarkerReachedSignal
events that I have laid out in animations.
The issue is that although the events behave and fire for the local player, the local player is not detecting these events for other players.
I think I’ve scavenged nearly all the resources here on the forum, previous topics, developer hub, etc… I’ve checked continuously with print statements and I’ve narrowed down the potential problem to my event handler. I just don’t know what the issue is - there are no errors in the output so I’m likely missing something.
I’d appreciate any help, suggestions, workarounds, or new ideas
Here’s the script, it’s in StarterPlayerScripts. The output only prints for the local player
-- Services
local Players = game:GetService("Players")
--____________________________________________________________________________________________
-- Specific functions to each of the props
local PropTable = {
Marshmallow = {},
Popsicle = {},
}
PropTable.Marshmallow.Squish = function(AnimTrack)
local Squish
Squish = AnimTrack:GetMarkerReachedSignal("Squish"):Connect(function()
print("Hi") -- This should print locally when any player fires this event
Squish:Disconnect()
end)
end
--___________________________________________________________________________________________________
-- Declaring the general animation function
local PropAnimations = function(AnimTrack)
if PropTable[AnimTrack.Animation.Name] then
for _, Function in pairs(PropTable[AnimTrack.Animation.Name]) do
Function(AnimTrack)
end
end
end
--_________________________________________________________________________________________
-- Getting humanoid events WOW IS THIS ANNOYING
local Humanoids = {}
-- Players that are already in the game
for _, Player in ipairs(Players:GetPlayers()) do
Player.CharacterAdded:Connect(function(ResetCharacter)
local ResetHumanoid = ResetCharacter:FindFirstChild("Humanoid")
if not ResetHumanoid then
ResetHumanoid = ResetCharacter:WaitForChild("Humanoid")
if Humanoids[Player.UserId] then
Humanoids[Player.UserId]:Disconnect()
end
Humanoids[Player.UserId] = ResetHumanoid.AnimationPlayed:Connect(PropAnimations)
end
end)
local Character = workspace:FindFirstChild(Player.Name)
if not Character then
Character = workspace:WaitForChild(Player.Name)
end
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then
Humanoid = Character:WaitForChild("Humanoid")
end
if Humanoids[Player.UserId] then
Humanoids[Player.UserId]:Disconnect()
end
Humanoids[Player.UserId] = Humanoid.AnimationPlayed:Connect(PropAnimations)
end
-- New players
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(ResetCharacter)
local ResetHumanoid = ResetCharacter:FindFirstChild("Humanoid")
if not ResetHumanoid then
ResetHumanoid = ResetCharacter:WaitForChild("Humanoid")
if Humanoids[Player.UserId] then
Humanoids[Player.UserId]:Disconnect()
end
Humanoids[Player.UserId] = ResetHumanoid.AnimationPlayed:Connect(PropAnimations)
end
end)
end)
Players.PlayerRemoving:Connect(function(Player)
if Humanoids[Player.UserId] then
Humanoids[Player.UserId]:Disconnect()
end
Humanoids[Player.UserId] = nil
end)