Attempt to index nil with nil?

Hi,

So right now I am trying to create a Health bar system that when a player is shot, it will appear, But I don’t want this visible for the Player, so i tried using a RemoteEvent, The most logical thing, but when doing so, it causes a lot as for some reason, the Game cant find what I’m assigning it to look for.

For some reason, it returns the Error: Attempt to index nil with nil, and I’m Confused.


I’m not sure if I need to explain anything, feel free to ask tho.

ModuleScript:

psvc.TweenService = game:GetService("TweenService")

psvc.Replicated = game.ReplicatedStorage
psvc.Events = psvc.Replicated.Events


psvc.J = game.Players.PlayerAdded
psvc.L = game.Players.PlayerRemoving

psvc.HealthGui = game.ReplicatedStorage.PlayerFrames.Health


function psvc.newframe(p: Player, char: Model)
	local C = psvc.HealthGui:Clone()
	local UGL = C.Back.UIGridLayout
	C.Parent = char.PrimaryPart
	
	char:FindFirstChildOfClass("Humanoid").HealthChanged:Connect(function(hp)
		psvc.TweenService:Create(UGL, TweenInfo.new(.4), {CellSize = UDim2.fromScale(hp/100, 1)}):Play()
	end)
	psvc.Events.RemoveUI:FireClient(p, C) -- error Line
end

Event:

local events = game.ReplicatedStorage:WaitForChild("Events")

events.RemoveUI.OnClientEvent:Connect(function(item)
	item:Destroy()
end)

Script requiring Module:

local svc = require(script.Parent.PlayerSvc)

svc.J:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		svc.newframe(p, c)
	end)
end)

Other than that, the code seems to work:

Screenshot (157)

Is it this part that is causing the error?

According to the images Provided, technically no.

What line is causing the problem then?

-- error line is the line firing the event, so thats the error line, and im confused on why it doesnt work

What is p and C defined as in the script?

What line are you taken to when you click the error in the output?

Events: Line 5:

events.RemoveUI.OnClientEvent:Connect(function(item) -- line 4
	item:Destroy() -- line 5
end) -- line 6
1 Like

Still wondering about this :frowning:

Maybe it confused C with the lowercase c in the script?

Thats not how that works

C is a local Variable, and those 2 arguments are applying Values.

Why not use the BillboardGui’s PlayerToHideFrom property?

1 Like

Is that your full module script? If so, the error can’t be coming from that line as that isn’t line 5. Could you show the full module and/or point out which script is PlayerScripts.Events at line 5?

On a side note, it might be a good idea to get into the habit of using better variable and index names as it’s very difficult to tell what’s going on and to keep track of things.

Try printing out the value of item in your client Event before you destroy it. I don’t believe you can send objects from server to client so it is probably your nil value.

No, I have more, I’m just showing something relevant

Yes it is

The module script isn’t the one causing the errors, its the event if you looked at the images, the only reason i said that was the error line is because that’s where its being called from.

I can read it and find stuff just fine, thats just you

I actually did not know that existed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.