Attempt to index nil with 'WaitForChild'

  1. What do you want to achieve?
    fix this bug below
  2. What is the issue?
    capture
  3. What solutions have you tried so far?
    tried to search many times on dev forum nothing helped
local ts = game:GetService("TweenService")
local Ss = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer --Error happening in this line 
local Gui = Player:WaitForChild("PlayersGui")
local Base = {}


function Base.Setup(Health,ui)      
	Base.HealthUI = Players.LocalPlayer.PlayerGui.Canvas.Upperinfo["Base Health"]
    Base.CurrentHealth = Health
    Base.MaxHealth = Health	   
end

function Base.DamageBase(damage)
	if damage then
	    Base.CurrentHealth -= damage
		local gui = Base.HealthUI

		local tweeninfo = TweenInfo.new(
			0.5,
			Enum.EasingStyle.Exponential,
			Enum.EasingDirection.In,
			0,
			false,
			0
		)

		local percentage = Base.CurrentHealth/Base.MaxHealth
         

		local goal = {} 
		goal.Size = UDim2.new(percentage,0,0.25,0)
        
        local tween = ts:Create(gui.CurrentHealth,tweeninfo,goal)
		tween:Play()
		gui.Title.Text = ("Base Health: ") .. (Base.MaxHealth) .. ("|") .. (Base.CurrentHealth) 
		if Base.CurrentHealth <= 0 then
			gui.Title.Text = ("Base Health: OOF")
			Ss.Bindables.GameOver:Fire()
		end
		
	end
end	




Ss.Bindables.DamageBase.Event:Connect(Base.DamageBase)	


return Base


If you’re requiring this module on the server, it simply wouldn’t work, since Players.LocalPlayer is a field only available to the client (LocalScripts)
I suggest you pass the player as a parameter/argument to the function. That’d work.

i copied this code from gnome code video and it was also a module of a server script and it did worked for him but not for me :c

Could you link it? With the timestamp preferably.

it was a long video but it was around the first timelapse around 3-10 mins note sure but may be mine didnt worked cuz i missed some steps becuase he was using bill board gui which i didnt wanted to use. 1 hour passed still waiting

Yeah this module is supposed to be for clients, really because it manipulates the gui.

im new to scripting can u tell me how to get the local player then C: pls

Make it a local script instead of a server script, for whichever script tries to require it and use the functions.

i cant because it requirs many diff modules both for client and server if i convert it into a server script then the whole game will break

You are probably requiring the wrong module, because this module needs to be required by the client, not by the server. Check if you got the name of the module right for both the instance and the script.

local Base = require(script.Base)
local mob = require(script.Mob)
local Unit = require(script.Unit)
local map = workspace.Grassland

local Ss = game:GetService(“ServerStorage”)
local rs = game:GetService(“ReplicatedStorage”)
local players = game:GetService(“Players”)
local PhysicsService = game:GetService(“PhysicsService”)
local ts = game:GetService(“TweenService”)

local GameOverEvent = Ss.Bindables:WaitForChild(“GameOver”)
local GameOver = false

Base.Setup(100,map)
GameOverEvent.Event:Connect(function()
GameOver = true
end)

for wave =1, 100 do
print(“WAVE STARTING:”, wave)
if wave < 100 then
mob.Spawn(“TankEnemy”, 300 * wave,map)
end

repeat
	task.wait(1)

until #workspace.Mobs:GetChildren() == 0 or GameOver
if GameOver then 
	print("Game Over")
	break
end
print("WAVE ENDED")
task.wait(1)

end

heres a script of thats requiring most of the modules
and i already gave the base module
idk whats wrong all spellings are correct
and its still a server script btw

PlayersGui doesn’t exist, you typed the wrong thing, the correct name is PlayerGui NOT PlayersGui, instead replace line 5 with.

local Gui = Player:WaitForChild("PlayerGui")
local Gui = Player:WaitForChild("PlayerGui") -- Took out s

i did take out the s but its still giving me warnig
attempt to index nil with 'WaitForChild'

Is it a local script? if yes then where is it located? in the StarterCharacterScripts or somewhere else?

local ts = game:GetService("TweenService")
local Ss = game:GetService("ServerStorage")
local Player = game:GetService("Players").LocalPlayer
local Gui = Player:WaitForChild("PlayerGui")
local Base = {}


function Base.Setup(Health,ui)      
	Base.HealthUI = Gui.Canvas.Upperinfo["Base Health"]
    Base.CurrentHealth = Health
    Base.MaxHealth = Health	   
end

function Base.DamageBase(damage)
	if damage then
	    Base.CurrentHealth -= damage
		local gui = Base.HealthUI

		local tweeninfo = TweenInfo.new(
			0.5,
			Enum.EasingStyle.Exponential,
			Enum.EasingDirection.In,
			0,
			false,
			0
		)

		local percentage = Base.CurrentHealth/Base.MaxHealth
         

		local goal = {} 
		goal.Size = UDim2.new(percentage,0,0.25,0)
        
        local tween = ts:Create(gui.CurrentHealth,tweeninfo,goal)
		tween:Play()
		gui.Title.Text = ("Base Health: ") .. (Base.MaxHealth) .. ("|") .. (Base.CurrentHealth) 
		if Base.CurrentHealth <= 0 then
			gui.Title.Text = ("Base Health: OOF")
			Ss.Bindables.GameOver:Fire()
		end
		
	end
end	




Ss.Bindables.DamageBase.Event:Connect(Base.DamageBase)	


return Base

its a module of a server script

copied your code but same problem ://

If you’re requiring it on the server, then LocalPlayer doesn’t exist, LocalPlayer is only accessible on the client, so if you require the module on a server script, it wont find anything, but if you require it on a Local script it will find it.

is there no way to get local player on server script (dont say no pls)