LoadAnimation not working in multiplayer but only single

The loadanimation works when im testing just only with single player, but when i test with 2 players it just couldnt load and I couldn’t figure out why

WaitForChild does not have any effects either

ReplicatedStorage = game:GetService("ReplicatedStorage")

Players = game:GetService("Players")

Events = ReplicatedStorage.Events

StatusUpdate = Events.StatusUpdate

Camera = workspace.CurrentCamera

Player = Players.LocalPlayer

UserID = Player.UserId

ThumbnailType = Enum.ThumbnailType.HeadShot

ThunmbnailSize = Enum.ThumbnailSize.Size420x420

Content = Players:GetUserThumbnailAsync(UserID, ThumbnailType, ThunmbnailSize)

PlayerHumanoid = nil

StatusImage = nil

StatusLabel = nil

StatusFilter = nil

function CharacterAdded(Character)

local PlayerGui = Player.PlayerGui

local UserInterface = PlayerGui:WaitForChild("UserInterface")

PlayerHumanoid = Character:WaitForChild("Humanoid")

StatusImage = UserInterface.StatusImage

StatusLabel = UserInterface.StatusLabel

StatusFilter = StatusImage.StatusFilter

StatusImage.Image = Content

end

function Status(Status, Filter, Color, AnimationID)

print( PlayerHumanoid)

local Animation = Instance.new("Animation")

Animation.AnimationId = AnimationID

local Track = PlayerHumanoid:LoadAnimation(Animation)

Track:Play()

StatusLabel.Text = Status

StatusFilter.ImageTransparency = 0

StatusFilter.Image = Filter

StatusFilter.ImageColor3 = Color

end

Player.CharacterAdded:Connect(CharacterAdded)

StatusUpdate.OnClientEvent:Connect(Status)
2 Likes

Before checking your script carefully, try with this code, I changed the LoadAnimation to load into the Animator not the Humanoid. Using the Animator is what Roblox suggest when loading animations:

ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
Events = ReplicatedStorage.Events
StatusUpdate = Events.StatusUpdate
Camera = workspace.CurrentCamera
Player = Players.LocalPlayer
UserID = Player.UserId
ThumbnailType = Enum.ThumbnailType.HeadShot
ThunmbnailSize = Enum.ThumbnailSize.Size420x420
Content = Players:GetUserThumbnailAsync(UserID, ThumbnailType, ThunmbnailSize)
PlayerHumanoid = nil
StatusImage = nil
StatusLabel = nil
StatusFilter = nil

PlayerAnimator = nil -- animator variable

function CharacterAdded(Character)
	local PlayerGui = Player.PlayerGui
	local UserInterface = PlayerGui:WaitForChild("UserInterface")
	PlayerHumanoid = Character:WaitForChild("Humanoid")
	PlayerAnimator = PlayerHumanoid:WaitForChild("Animator") -- Setting the animator into variable
	StatusImage = UserInterface.StatusImage
	StatusLabel = UserInterface.StatusLabel
	StatusFilter = StatusImage.StatusFilter
	StatusImage.Image = Content
end

function Status(Status, Filter, Color, AnimationID)
	print( PlayerHumanoid)
	warn("The animator:", PlayerAnimator)
	local Animation = Instance.new("Animation")
	Animation.AnimationId = AnimationID
	local Track = PlayerAnimator:LoadAnimation(Animation) -- Using the animator
	Track:Play()
	StatusLabel.Text = Status
	StatusFilter.ImageTransparency = 0
	StatusFilter.Image = Filter
	StatusFilter.ImageColor3 = Color
end

Player.CharacterAdded:Connect(CharacterAdded)

StatusUpdate.OnClientEvent:Connect(Status)
1 Like

image

It still couldnt, and the humanoid just sets to nil only in multiplayer test

1 Like

Probably its because this line:
Player.CharacterAdded:Connect(CharacterAdded)

This is a client script, that start to run when the script is added into the character or player.
And you are connecting a function that fires everytime a new Character is added into game. Causing that the player get multiple calls of that function everytime a player joins.

Try this:

ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
Events = ReplicatedStorage.Events
StatusUpdate = Events.StatusUpdate
Camera = workspace.CurrentCamera
Player = Players.LocalPlayer
UserID = Player.UserId
ThumbnailType = Enum.ThumbnailType.HeadShot
ThunmbnailSize = Enum.ThumbnailSize.Size420x420
Content = Players:GetUserThumbnailAsync(UserID, ThumbnailType, ThunmbnailSize)
PlayerHumanoid = nil
StatusImage = nil
StatusLabel = nil
StatusFilter = nil

PlayerAnimator = nil

local Character = Player.Character or Player.CharacterAdded:Wait() -- The character of this player

local PlayerGui = Player:WaitForChild("PlayerGui")
local UserInterface = PlayerGui:WaitForChild("UserInterface")
PlayerHumanoid = Character:WaitForChild("Humanoid")
PlayerAnimator = PlayerHumanoid:WaitForChild("Animator")
StatusImage = UserInterface.StatusImage
StatusLabel = UserInterface.StatusLabel
StatusFilter = StatusImage.StatusFilter
StatusImage.Image = Content

function Status(Status, Filter, Color, AnimationID)
	print( PlayerHumanoid)
	local Animation = Instance.new("Animation")
	Animation.AnimationId = AnimationID
	local Track = PlayerAnimator:LoadAnimation(Animation)
	Track:Play()
	StatusLabel.Text = Status
	StatusFilter.ImageTransparency = 0
	StatusFilter.Image = Filter
	StatusFilter.ImageColor3 = Color
end

StatusUpdate.OnClientEvent:Connect(Status)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.