✓ Accepted answer
#Ancestry
###The top ancestor (excluding the DataModel and the Players service) of a LocalScript is, well, the LocalPlayer. Scripts run on the server, whilst LocalScripts run on the client.
#Why LocalPlayer is nil on the server
###Think of it as your school classroom. Your desk is your desk, just like how your LocalScript is your LocalScript, it works for you. But your classroom is your classroom, and in it are your classmates as well as your teacher. Think of the classroom as the server. It has everyone in it, and if your game has multiple players in it, it can't randomly choose who LocalPlayer is! For this reason, LocalPlayer is nil on the server. Code cannot your mind. This is why it must be all typed out. So instead of doing this:
make a part inside of the workspace with color red
###You must do this:
local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Really red")
part.Parent = workspace
###The solution to your problem would be to simply use a LocalScript, as Scripts do not run in PlayerGui. They run in PlayerGui from Play Solo, and ran when Experimental Mode existed, but with that mode gone this is no longer the case in a server.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Coins = Player.PlayerGui.Coins
local CoinDisplay = script.Parent.Stats.Coins.CoinsDisplay
local function SetCoins()
CoinDisplay.Text = tostring(Coins.Value)
end
Coins.Changed:Connect(SetCoins)
1 comment
Change it to a LocalScript, use LocalPlayer, and problem solved.