My Goal: To clone a GuiObject (TextLabel) into every player in the current servers PlayerGui when FocusLost() from TextBox.
So hey developers, I’ve been lookin at different ways to achieve new variations of creating chat gui’s, and figured I’d restart from scratch. Now I’ve ran into a problem with replicating it across every active players server.
It’s very simple to explain as to how this works;
Step 1:
Player Types inside TextBox in their GUI.
Step 2:
Player either presses “Enter” or on the FocusLost() Event, fire remote event containing message.
Step 3:
Server clones a TextLabel in ReplicatedStorage, then places the cloned object into every players chat gui.
This only seems to work for the last player that loaded in. Here is the respective versions of the code below. Any and all help solving this problem is appreciated!
--// Local script
--// Check if chatting/chatted
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.Slash then
wait(.01)
chatBar.ClearTextOnFocus = true
chatBar:CaptureFocus()
chatBar.Text = ""
end
end)
chatBar.FocusLost:Connect(function()
local message = ""..chatBar.Text
local filtercheck = ""..string.lower(message)
for i, word in pairs(badWordsList) do
if string.find(filtercheck, word) then
plr.Warnings.Value = plr.Warnings.Value + 1
message = "Filtered"
script.Parent.lert.Visible = true
plr.PlayerGui.Main.MenuSounds.Alert:Play()
end
end
--wait(.001)
chatRemote:FireServer(message)
chatBar.Text = "Press '/' or click here to chat"
wait(1)
script.Parent.alert.Visible = false
plr.PlayerGui.Main.MenuSounds.Alert:Stop()
end)
--// Server Script
chatted.OnServerEvent:Connect(function(plr,message)
print("fired")
--// Create and set new chat item
local chatMsg = game.ReplicatedStorage.Msg
local clonedMsg = chatMsg:Clone()
clonedMsg.Text = plr.Name..": "..message
print("made")
for i, user in pairs(game:GetService("Players"):GetChildren()) do
if table.find(playerTable, user.Name) then
clonedMsg.Parent = user.PlayerGui.Chat.ChatFrame.Frame
local chatAmount = #user.PlayerGui.Chat.ChatFrame.Frame:GetChildren()
clonedMsg.TextNumber.Value = chatAmount
if chatAmount == 10 then
clonedMsg.Name = "LastMessage"
end
if message == "Filtered" then
message = message.."("..plr.Warnings.Value..")"
end
end
end
--// remove old chat if full, do textvalue additions
for i, user in pairs(game:GetService("Players"):GetChildren()) do
if table.find(playerTable, user.Name) then
if #user.PlayerGui.Chat.ChatFrame.Frame:GetChildren() == 10 then
user.PlayerGui.Chat.ChatFrame.Frame:FindFirstChild("LastMessage"):Destroy()
for i, j in pairs(user.PlayerGui.Chat.ChatFrame.Frame:GetChildren()) do
if j:IsA("TextLabel") then
local value = j:FindFirstChild("TextNumber")
value.Value = value.Value + 1
end
end
end
end
end
end)