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

1 comment
I'm confused as to what you're doing with "Stat" is it an IntValue? If so, then return the value instead of the IntValue itself. And your return(on the server) should return something if the If statement were to fail.