I have a button and when the button is clicked it actives a remote event which leads straight to the server. In the server script, it creates an 'imageLabel' and then sets the player's head to the imageLabel. However, as it is server-sided I expected it to show for everyone, however, it only shows for the local player.
The only issue is that it only shows in the client's screen, but doesn't show everywhere else. I want it to show the local player who clicked the button on everyone's screen.
I've looked everywhere for the solution to my problem but haven't come across anything, that's why I resulted to trying here.
This is what I have tried:
Local script:
script.Parent.readyToStart.MouseButton1Click:Connect(function(player) remoteEventPlayer:FireServer(player) end)
Server script:
local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto local function playerPhoto(player) --setting up the image label print(player.Name) local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto local typingChallenge = player.PlayerGui.typingChallenge local otherRacePosition = typingChallenge.otherRacePosition local newImage = Instance.new("ImageLabel", otherRacePosition) newImage.Name = player.Name newImage.Position = UDim2.new(0, 0,0, 0) newImage.Size = UDim2.new(0.06, 0,0.998, 0) newImage.BackgroundTransparency = 1 -- setting the image label to the player's head local UserId = player.UserId local thumbType = Enum.ThumbnailType.HeadShot local thumbSize = Enum.ThumbnailSize.Size100x100 local players = game:GetService("Players") local content, isReady = players:GetUserThumbnailAsync(UserId, thumbType, thumbSize) newImage.Image = content end remoteEventLocalPhoto.OnServerEvent:Connect(playerPhoto)
script.Parent.readyToStart.MouseButton1Click:Connect(function() -- this breaks the full script remoteEventPlayer:FireServer() -- dont put player there its not needed end)
that's all, everything else is fine
Your problem is that OnServerEvent passes only the player that fired it, and other optional arguments, to fix this you have to loop between every player to get the desired effect. Your server script should look like:
local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto local players = game:GetService("Players") local function playerPhoto(receivingplayer, sendingplayer) --setting up the image label print(receivingplayer.Name) local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto local typingChallenge = receivingplayer.PlayerGui.typingChallenge local otherRacePosition = typingChallenge.otherRacePosition local newImage = Instance.new("ImageLabel", otherRacePosition) newImage.Name = sendingplayer.Name newImage.Position = UDim2.new(0, 0,0, 0) newImage.Size = UDim2.new(0.06, 0,0.998, 0) newImage.BackgroundTransparency = 1 -- setting the image label to the player's head local UserId = sendingplayer.UserId local thumbType = Enum.ThumbnailType.HeadShot local thumbSize = Enum.ThumbnailSize.Size100x100 local content, isReady = players:GetUserThumbnailAsync(UserId, thumbType, thumbSize) newImage.Image = content end remoteEventLocalPhoto.OnServerEvent:Connect(function(player) --loop a table of every player for i, v in pairs (players:GetPlayers()) do playerPhoto(v, player) end end)
Edit: You also do not need to pass the LocalPlayer in :FireServer(), as it is already the first parameter in OnServerEvent