Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Doesn't a server-sided script creating a GUI make it visible to everyone?

Asked by 4 years ago
Edited 4 years ago
  1. What do you want to achieve?

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.

  1. What is the issue?

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.

  1. What solutions have you tried so far?

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)

0
I recommend adding an output. raid6n 2196 — 4y

2 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
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

0
dont use playerrr raid6n 2196 — 4y
0
This doesn't work, it still only shows the GUI on player 1's screen and not player 2's. RyanTheLion911 195 — 4y
Ad
Log in to vote
0
Answered by
iloveu6 20
4 years ago
Edited 4 years ago

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

Answer this question