What do you want to achieve? Keep it simple and clear!
Hello, I want to make a Owner join notification on the screen instead of in the chat. So, when a player joins the game it will check the UserId if it matched then the remote event will fire to the server after that the server will make the notification visible to everybody on the server. After 5s the text will fade away and they will also get 50 extra coins added to their leaderstats.
What is the issue? Include screenshots / videos if possible!
I have a problem with my script it gives me this error and the notification Gui doesn’t show to everyone. ServerScriptService.Script:8: attempt to index nil with 'WaitForChild'
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for solution on google as well as on developer forum but couldn’t find a fix to it.
-- localscript
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local Notifier = script.Parent:WaitForChild("TextLabel")
local OwnerUserId = "1533601134"
local player = game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
if player.UserId == OwnerUserId then
Join:FireServer()
end
end)
-- ServerScript
local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local RunTime = 3 + 2
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local Notifier = PlayerGui:WaitForChild("TextLabel")
Join.OnServerEvent:Connect(function()
if Notifier.Visible == false then
Notifier.Visible = true
wait(RunTime)
local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
local P = {Notifier.TextTransparency == 1}
local X = tweenservice:Create(Notifier, A, P)
X:Play()
end
end)
end)
Oh, I have changed it but why does it says this in the output? W is not a valid member of PlayerGui "Players.SingaporeSteadyLah.PlayerGui"
[EDIT] btw here is the script
local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local RunTime = 3 + 2
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local Player = game:GetService("Players")
local Notifier = player.PlayerGui.W:WaitForChild("TextLabel")
Join.OnServerEvent:Connect(function()
if Notifier.Visible == false then
Notifier.Visible = true
wait(RunTime)
local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
local P = {Notifier.TextTransparency == 1}
local X = tweenservice:Create(Notifier, A, P)
X:Play()
end
end)
end)
-- ServerScript (sorry for changing name of event)
local OwnerUserId = "1533601134"
game.Players.PlayerAdded:Connect(function(player)
if player.UserId == OwnerUserId then
OwnerJoinEvent:FireAllClients()
end
end)
--client script
OwnerJoinEvent.OnClientEvent:Connect(function()
--check local player is not the owner.
--play effect
end)
Ok so I moved the owner join event firing to the server because the way you had it, an exploiter could fire that event from the client, server sees it as valid and cause problems. I then fired the client to play the effect on the client instead of the server because this removes load from the server. You shouldn’t have the wait for child problem as it is on the client.
If your WaitForChild errors persist, I recommend checking this awesome video by Sleitnick where he explains what causes the WaitForChild error and ways to get around it.
Okay, so I did what you said I fired the remote event from the Server to the Client and make the Notification Gui visible, now no more errors but it print Owner not found on ServerScript when checking the UserId… Why does it do that?
-- LocalScript
local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local Notifier = script.Parent:WaitForChild("TextLabel")
local RunTime = 3 + 2
game.Players.PlayerAdded:Connect(function(player)
Join.OnClientEvent:Connect(function()
if player.UserId == OwnerUserId then
print("Ensureing UserId Match with OwnerUserId")
print(OwnerUserId)
if Notifier.Visible == false then
Notifier.Text = "{Owner} - SingaporeSteadyLah has joined the game! You received 50 extra Coins!"
Notifier.Visible = true
wait(RunTime)
local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
local P = {Notifier.TextTransparency == 1}
local X = tweenservice:Create(Notifier, A, P)
X:Play()
else
print("Error or Owner not found!")
end
end
end)
end)
-- ServerScript
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
if player.UserId == OwnerUserId then
print("Owner found!")
Join.FireAllClient()
else
print("Owner not found!")
end
end)
For your information, having the local script is absolutely useless and redundant. You can hande all of this on the server without any events, like this:
-- Server script
local players = game.Players
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local ownerId = "1533601134"
local notifier = replicatedStorage:WaitForChild("Notifier") -- Put the notifier in ReplicatedStorage
local waitTime = 3 + 2
players .PlayerAdded:Connect(function(player)
if player.UserId == ownerId then
print("Owner found!")
notifier.Text = "{Owner} - SingaporeSteadyLah has joined the game! You received 50 extra Coins!"
notifier.Visible = true
for i = 0, #players :GetPlayers(), 1 do
notifier.Parent = players[i]:WaitForChild("PlayerGui"):WaitForChild("YourScreenGuiNameHere")
end
task.wait(waitTime)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
local tween = tweenService:Create(notifier, tweenInfo , {TextTransparency = 1})
tween:Play()
else
print("Owner not found!")
end
end)
wait() should never be used. Even if there’s no parameter, it can wait up to 1 second. task.wait() is much more accurate and if you compare wait() vs task.wait() (with no seconds provided), task.wait() is 2x times faster. But even if you give it an amount of seconds to wait, like wait(5), the default function is still much less accurate. Always use task.wait() to wait a precise amount of time.
because of this thread i learnt about the task library update and no longer have to use a custom thread module to handle wait and fastspawn. I really should check announcements more often.