String help | Roblox Forum
Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

String help

  • This website was created by Roblox members to replace the official forums because Roblox shut them down! Join our community if you like to talk about Roblox!

collycoolguyguy111

New Member
Reputation: 0 / 0 / 0
Nov 21, 2020
1
0
1
Roblox
collycoolguyguy111
So I am making a script that says who joined and who left. Here is my script.
game.Players.PlayerAdded:Connect(function(player)
local lol = Instance.new("Hint")
lol.Parent = game.Workspace
lol.Text = player.name "Has joined"
wait(5)
lol.Parent = nil
end)
game.Players.PlayerRemoving:Connect(function(player)
local lol = Instance.new("Hint")
lol.Parent = game.Workspace
lol.Text = player.name "Has left"
wait(5)
lol.Parent = nil
end)
Why will this not work? The hint is added but nothing is in the textbox
 

CallMeKY

Moderator
Ultra
Reputation: 5 / 0 / 0
Feb 25, 2018
1,385
495
83
Maine, USA
Roblox
CallMeKY
Discord
CallMeKY#5012
So I am making a script that says who joined and who left. Here is my script.
game.Players.PlayerAdded:Connect(function(player)
local lol = Instance.new("Hint")
lol.Parent = game.Workspace
lol.Text = player.name "Has joined"
wait(5)
lol.Parent = nil
end)
game.Players.PlayerRemoving:Connect(function(player)
local lol = Instance.new("Hint")
lol.Parent = game.Workspace
lol.Text = player.name "Has left"
wait(5)
lol.Parent = nil
end)
Why will this not work? The hint is added but nothing is in the textbox
Looks like your problem is with not concatenating and not capitalizing the "Name" property of the player object. Hints are also deprecated in favor of GUI, so I'd recommend against using them. I admittedly had a little too much fun playing with the new rich text feature since I haven't had a good excuse to yet, so I wrote up a simplified script that behaves the same as a hint would as well. Both of these should be in a LocalScript parented to StarterPlayerScripts.

Rich Text
Code:
local displayTime = 5

local players = game:GetService('Players')

local screenGui = Instance.new('ScreenGui', players.LocalPlayer:WaitForChild('PlayerGui'))
local textLabel = Instance.new('TextLabel')
textLabel.BackgroundColor3 = Color3.new(0, 0, 0)
textLabel.BorderSizePixel = 0
textLabel.Size = UDim2.new(1, 0, 0.05, 0)
textLabel.TextSize = 50
textLabel.Font = Enum.Font.Code
textLabel.RichText = true

local joinedQueue, running, connection = {}, false, nil

local function adjustTextSize(textLabel)
    local sizeGoal = screenGui.AbsoluteSize.Y * textLabel.Size.Y.Scale - 2
    if textLabel.TextSize > sizeGoal then
        repeat textLabel.TextSize -= 1 until textLabel.TextSize <= sizeGoal
    elseif textLabel.TextSize < sizeGoal then
        repeat textLabel.TextSize += 1 until textLabel.TextSize >= sizeGoal
    end
end

local function playersChanged()
    if running then return end
    running = true
    while #joinedQueue > 0 do
        local newTextLabel = textLabel:Clone()
        if joinedQueue[1].PlayerJoined then
            newTextLabel.Text = '<b><font color= "#ffffff">[</font><font color= "#00ff00">+</font><font color= "#ffffff">]</font><font color= "#55aaff"> ' .. joinedQueue[1].PlayerName .. '</font></b>'
        else
            newTextLabel.Text = '<b><font color= "#ffffff">[</font><font color= "#ff0000">-</font><font color= "#ffffff">]</font><font color= "#55aaff"> ' .. joinedQueue[1].PlayerName .. '</font></b>'
        end
        adjustTextSize(newTextLabel)
        newTextLabel.Parent = screenGui
        if connection then connection:Disconnect() end
        connection = screenGui:GetPropertyChangedSignal('AbsoluteSize'):Connect(function() adjustTextSize(newTextLabel) end)
        table.remove(joinedQueue, 1)
        wait(displayTime)
        newTextLabel:Destroy()
    end
    if connection then connection:Disconnect() end
end

players.PlayerAdded:Connect(function(player)
    table.insert(joinedQueue, {PlayerName = player.Name, PlayerJoined = true})
    playersChanged()
end)

players.PlayerRemoving:Connect(function(player)
    table.insert(joinedQueue, {PlayerName = player.Name, PlayerJoined = false})
    playersChanged()
end)

Hint Replica
Code:
local displayTime = 5

local players = game:GetService('Players')

local screenGui = Instance.new('ScreenGui', players.LocalPlayer:WaitForChild('PlayerGui'))
local textLabel = Instance.new('TextLabel')
textLabel.BackgroundColor3 = Color3.new(0, 0, 0)
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.BorderSizePixel = 0
textLabel.Size = UDim2.new(1, 0, 0.04, 0)
textLabel.TextScaled = true
textLabel.Font = Enum.Font.SourceSans

local joinedQueue, running = {}, false

local function playersChanged()
    if running then return end
    running = true
    while #joinedQueue > 0 do
        local newTextLabel = textLabel:Clone()
        if joinedQueue[1].PlayerJoined then
            newTextLabel.Text = joinedQueue[1].PlayerName .. ' has joined the server!'
        else
            newTextLabel.Text = joinedQueue[1].PlayerName .. ' has left the server!'
        end
        newTextLabel.Parent = screenGui
        table.remove(joinedQueue, 1)
        wait(displayTime)
        newTextLabel:Destroy()
    end
end

players.PlayerAdded:Connect(function(player)
    table.insert(joinedQueue, {PlayerName = player.Name, PlayerJoined = true})
    playersChanged()
end)

players.PlayerRemoving:Connect(function(player)
    table.insert(joinedQueue, {PlayerName = player.Name, PlayerJoined = false})
    playersChanged()
end)
 
Private conversations
Rules Help Users
    You haven't joined any rooms.