Ad
Log in to vote
0

How can I make this server script to share information about a player with the whole server work?

Asked by 17 days ago
Edited 17 days ago

I’m trying to make it so that when a player touches a certain part (named “Trigger”), information about that player (an image of them, their name, and their account age) will be transmitted to the whole server, and players will be able to access that information via a ScreenGui in their PlayerGui. Currently, aforementioned ScreenGui is merely left blank when the trigger is touched, and the output doesn’t give any suggestion as to how I should improve my script, so if anyone could help me identify the error(s) it would be greatly appreciated.

local Players = game:GetService("Players")

workspace.Trigger.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        Players.PlayerAdded:Connect(function(Player)
            local PlayerGui = Player:WaitForChild('PlayerGui')
            local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
            local frame = ScreenGui:WaitForChild("Frame")
            local textButton = frame:WaitForChild("TextButton")
            local userId = player.UserId
            local thumbType = Enum.ThumbnailType.AvatarBust
            local thumbSize = Enum.ThumbnailSize.Size420x420
            local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
            frame.PlayerImage.Image = content
            local DT = DateTime.fromUnixTimestamp(86400 * player.AccountAge)
            local Days = tonumber(DT:FormatUniversalTime("DD", "en-us"))
            local Months = tonumber(DT:FormatUniversalTime("MM", "en-us"))
            local Years = tonumber(DT:FormatUniversalTime("YYYY", "en-us")) - 1970
            textButton.Text  = player.Name.. ", ".. Years
        end)
    end
end)

Answer this question