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)
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.
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