Any time that I attempt to use the remote function, I get an error saying that I am attempting to call a nil value on line 9 in my local script, but all values are loaded into the game already. Any help is appreciated.
Local:
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character CoinGUI = script.Parent.Coins GemGUI = script.Parent.Gems GetStatsInvoke = game:GetService("ReplicatedStorage"):WaitForChild("GetStatsInvoke") game.Players.LocalPlayer:WaitForChild("InGame").Changed:Connect(function() CoinGUI:FindFirstChild("CoinAmount").Text = (tostring(GetStatsInvoke:InvokeServer("Coins").Value).." Coins") GemGUI:FindFirstChild("GemAmount").Text = (tostring(GetStatsInvoke:InvokeServer("Gems").Value).." Gems") end)
Server:
GetStatsInvoke = game:GetService("ReplicatedStorage"):WaitForChild("GetStatsInvoke") StatsFolder = game:GetService("ServerStorage"):WaitForChild("PlayerStats") GetStatsInvoke.OnServerInvoke = function(plr, Stat) local plrFolder = StatsFolder:WaitForChild(plr.Name) if plrFolder:WaitForChild(Stat) ~= nil then local Return = plrFolder:WaitForChild(Stat) return Return end end
I think the main problem is when you set up CoinGUI and GemGUI. Just because the script is loaded does not mean all the other objects loaded, so when it tries to find "Coin", it hasn't been created yet, making the variable nil. Try changing lines 3 and 4 to this:
CoinGUI = script.Parent:WaitForChild("Coins") GemGUI = script.Parent:WaitForChild("Gems")