It just won’t work! for some reason.
Here is my script
for i, v in pairs(game.Players:GetPlayers()) do
local Notif = Instance.new("TextLabel", v.PlayerGui.OtherNotifHolder)
local Gradient = script.Sample:Clone()
Gradient.Parent = Notif
-- there is more script here but here is main cause
end
-- the func it's wrapped in
wait()
start(true, 4) <--
I would love to help with your script but I’m a little unclear on what the problem is right now. You said the for loop “won’t work” what is it doing that you don’t want it to do, or what is it not doing that you want it to do? Please me more clear when asking for help.
function start(count, for_)
if count == true then
for i, v in pairs(game.Players:GetPlayers()) do
local Notif = Instance.new("TextLabel", v.PlayerGui.OtherNotifHolder)
local Gradient = script.Sample:Clone()
Gradient.Parent = Notif
Notif.TextScaled = true
Notif.AnchorPoint = Vector2.new(0.5, 0.5)
end
end
end
wait()
start(true, 4)
What solutions have you tried so far? Did you look for solutions on the Developer Hub ?
I have tried using :WaitForChild() and :FindFirstChild(). They both give no errors and don’t work.
As for the Developer Hub, I have searched.
From what little I was able to understand, there is an important question that you must understand (something that I also had doubts in the beginning):
Roblox has Server and Local concepts:
If you use any ScreenGui elements, you must do so in LocalScript because this is the script that runs on the player’s machine (Client);
This way, I don’t think it is necessary to scan a list of players, but you can do this by simply entering a code at the beginning of LocalScript, which will be executed for each player, each time the player enters the game.
It is also important to understand that every time a player enters, a ScreenGui is automatically replicated to game.Players, so ideally, you should NOT interact directly with game.StarterGui, but with everything that is replicated within game.Players.LocalPlayer.
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Gui = PlayerGui:WaitForChild("ScreenGui")
Alright, let me give you some code to try. One thing you’re doing in your code is setting the parent of Notif “Text Label” instance with the second argument. I believe this practice was deprecated instead opting for Notif.Parent = v.PlayerGui.OtherNotifHolder. One thing you can try is checking if it even exists before parenting it to make sure the loop is finding the correct object to parent to.
function start(count, for_)
if count == true then
for i, v in pairs(game.Players:GetPlayers()) do
local onh = v.PlayerGui:FindFirstChild("OtherNotifHolder")
if not onh then warn("OtherNotifHolder not found for", v) continue end
local Notif = Instance.new("TextLabel")
local Gradient = script.Sample:Clone()
Gradient.Parent = Notif
Notif.TextScaled = true
Notif.AnchorPoint = Vector2.new(0.5, 0.5)
Notif.Parent = onh
end
end
end
wait()
start(true, 4)
function start(count, for_)
if count == true then
for i, v in pairs(game.Players:GetPlayers()) do
local onh = v.PlayerGui:FindFirstChild("OtherNotifHolder")
if not onh then
warn("OtherNotifHolder could not be found in", v)
continue
end
local Notif = Instance.new("TextLabel")
local Gradient = script.Sample:Clone()
Gradient.Parent = Notif
Notif.TextScaled = true
Notif.Parent = onh
Notif.AnchorPoint = Vector2.new(0.5, 0.5)
Notif.Font = Enum.Font.AmaticSC
Notif.TextColor3 = Color3.new(255, 255, 255)
Notif.Size = UDim2.new(1, 0, 0.084, 0)
Notif.Position = UDim2.new(0, 479, 0, 25)
Notif.TextColor3 = Color3.fromRGB(255, 255, 255)
Notif.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
end
end
end
Gave no warnings, but still, nothing pops up on my screen’
I tried removing the functions count and for_, plus the if loop.
If you run this right away, there may be no players in the game yet, so there will be nothing to loop through. Use PlayerAdded in your code in addition to the loop to catch those who join the game.