Ok so I know I have asked similar questions like this, but this time, I have a script. It is supposed to show an image label of a player, but it doesn’t. Please point out any errors I made, because there probably a ton…
function GetPlayerWithMostKills()
local current, plr = 0, nil
for i, v in pairs(game.Players:GetChildren()) do
if v.leaderstats.Kills.Value > current then
plr = v
end
end
return plr
end
--when round ends
PlayerWithMostKills = GetPlayerWithMostKills()
print(PlayerWithMostKills)
local Players = game:GetService("Players")
game:GetService('Players'):GetPlayers():WaitForChild('PlayerGui').MostKills.Enabled = true
local player = Players.LocalPlayer
local userId = PlayerWithMostKills.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local imageLabel = game.StarterGui.MostKills.Frame.PlrImage
imageLabel.Image = content
imageLabel.Size = UDim2.new(0, 166,0, 154)
This script is in serverscriptservice and also, when I don’t kill anyone, it prints “nil” and the script stops working.
There’s your issue, StarterGui’s descendants are only replicated on spawn (or only on join if ResetOnSpawn is false).
I’d recommend integrating a RemoteEvent where you call FireAllClients with the information (maybe as a dictionary) and a LocalScript, inside the UI, Connects upon OnClientEvent which applies the arrived information.
--// LocalScript, inside UI
game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent:Connect(function(Information)
--// Now do what you'd like with the dictionary
end)
Also, would you be able to show your ‘GetPlayerWithMostKills’ function? Seemingly, it’s returning nil.
Also, inside your ‘GetPlayerWithMostKills’ function I’d recommend defining current as -1 since if no-one has >0 kills then plr will stay nil. Make to assign current to the Player’s kills otherwise it’ll stay constant and pick any Player.
now it says: ServerScriptService.GameManager:41: attempt to call a nil value (That’s the game:GetService(‘Players’):GetPlayers():WaitForChild(‘PlayerGui’).MostKills,Enabled = true part)
You need to iterate through the GetPlayers array in order to reach each Player’s PlayerGui. I endorse against doing this however; you should assign Enabled in the LocalScript.