-
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. -
What is the issue? Include screenshots / videos if possible!
error - attempt to index nil with “FireClient”
-
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)

