So im trying to get every players name and clone it in gui showing their name, but this script clones the same players name every 20 seconds and so im not sure how to make it so it clones only one time per player
local players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")
local templates = RP:WaitForChild("Templates")
local tradingTemplate = templates:WaitForChild("TradingFrame")
while wait() do
for i, player in pairs(players:GetPlayers()) do
local newTemplate = tradingTemplate:Clone()
newTemplate.Parent = script.Parent
newTemplate:WaitForChild("playerName").Text = player.Name
end
wait(20)
end
local players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")
local templates = RP:WaitForChild("Templates")
local tradingTemplate = templates:WaitForChild("TradingFrame")
for i, player in pairs(players:GetPlayers()) do
local newTemplate = tradingTemplate:Clone()
newTemplate.Parent = script.Parent
newTemplate:WaitForChild("playerName").Text = player.Name
end
wait(20)
end
local players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")
local templates = RP:WaitForChild("Templates")
local tradingTemplate = templates:WaitForChild("TradingFrame")
players.PlayerAdded:Connect(function(player)
local newTemplate = tradingTemplate:Clone()
newTemplate:WaitForChild("playerName").Text = player.Name
newTemplate.Parent = script.Parent
end)
I am not sure if you want to clone it once when the player joins. Or maybe you are trying to replicate it to the player every 20 seconds. Clarify it.
To detect if the player has the GUI on their folder, FindFirstChild may be useful for you.
local players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")
local templates = RP:WaitForChild("Templates")
local tradingTemplate = templates:WaitForChild("TradingFrame")
while wait() do
for i, player in pairs(players:GetPlayers()) do
if not player:FindFirstChild("TradingFrame") then
local newTemplate = tradingTemplate:Clone()
newTemplate.Parent = player
newTemplate:WaitForChild("playerName").Text = player.Name
end
end
wait(20)
end
ServerScriptService is where the script should be stored.
A question, is the parent of the script only going to contain these trading templates? If so, I recommend moving the script outside of it, making a variable that references it and using :ClearAllChildren() on it before adding the templates again if you’re doing a refresh feature thing
It’s on the client? I’m so confused why are you handling other players things from the client. Only handle each player on their respective machine. (beside the fact it’s impossible to replicate or change things on other clients from one client)