Attempt to index nil with FireClient

  1. What do you want to achieve? Keep it simple and clear!
    on part click - give gold to gold stat stored in server storage and fire client to update ui.

  2. What is the issue? Include screenshots / videos if possible!
    error - attempt to index nil with “FireClient”


  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have an almost identical system set up in one of my other places THAT WORKS FLAWLESSLY (I use a different studio for testing systems, trial and error, etc.) - I’m still learning.

SERVER SCRIPT FOR CLICK DETECTOR

serverStorage = game:GetService("ServerStorage")
replicatedStorage = game:GetService("ReplicatedStorage")

local RemoteStats = replicatedStorage:WaitForChild("RemoteStats")
local event = RemoteStats:FindFirstChild("GoldCoins")

game.Players.PlayerAdded:Connect(function(player)
	wait(1)
	for i, child in pairs(serverStorage:GetChildren()) do
		if child:IsA("Folder") then
			if child.Name == player.Name then
				goldCoins = child:WaitForChild("Gold")
			end
		end
	end
	event:FireClient(player, goldCoins.Value)
end)


LOCAL SCRIPT TO UPDATE UI:

serverStorage = game:GetService("ServerStorage")
replicatedStorage = game:GetService("ReplicatedStorage")

local remoteStats = replicatedStorage:WaitForChild("RemoteStats")
local event = remoteStats:FindFirstChild("GoldCoins")

local player = game.Players.LocalPlayer

local textLabel = script.Parent


for i, child in pairs(serverStorage:GetChildren()) do
	if child:IsA("Folder") then
		if child.Name == player.Name then
			local playerName = child.Name
			local PlayerStats = serverStorage:WaitForChild(playerName)
			GoldCoins = PlayerStats:WaitForChild("GoldCoins")
		end
	end
end

local function updateGold(Gold)
	textLabel.Text = ""..Gold
end

while true do
	wait(.1)
	if player.Character.Humanoid.Health >= 0 then
		event.OnClientEvent:Connect(updateGold)
	end
end

GoldCoins.Changed:Connect(function()
	event.OnClientEvent:Connect(updateGold)
end)

event.OnClientEvent:Connect(updateGold)

1 Like

Is “Gold” event a remoteevent?

1 Like

I have such bad words right now. You have no idea. Problem solved. I’ve been staring at these scripts all day and thought I had checked that, turns out I need to open my eyes.

Thank you … UGH LOL

1 Like

So the Gold event wasn’t a remote? (Just checking?)
If so just keep that in mind when you are scripting! Goodluck!

1 Like

I forgot, I renamed the event to GoldCoins, so Gold was not a remote. Eh, a good learning experience I guess. lol. Thank you so much for your reply

3 Likes