Cannot get game.creatorid from Client

So I wanted to get the game.CreatorId but the thing is it returns ‘0’ and it dosen’t work. I tried using RemoteEvents but it didn’t work, just return ’ '. Here are the scripts:

Server

local players = game:GetService('Players')

local name = players:GetPlayerByUserId(game.CreatorId)

script.Parent.argPass:FireAllClients(name, game.Name)

Client

local players = game:GetService('Players')
local startergui = game:GetService('StarterGui')

local argPass = game:GetService('ReplicatedStorage'):WaitForChild('5CLoaderAssets'):WaitForChild('argPass')
local bg = script.Parent:WaitForChild('bg')

local bar = bg:WaitForChild('bar_0').bar
local name = bg:WaitForChild('creator')
local gameName = bg:WaitForChild('game_name')

local userRealName = ''
local realGameName = ''

argPass.OnClientEvent:Connect(function(user_id, game_name)
	userRealName = user_id
	realGameName = game_name
end)

function loadAssets()
	name.Text = userRealName
	gameName.Text = realGameName
end

loadAssets()

Edit

It seems that it’s not registering the OnClientEvent and returns back the normal value of userRealName which is ’ '. I treid putting ‘Not found’ in the value and it seems like it.

Seems like your game is owned by a group, you need to use DataModel | Roblox Creator Documentation

Edit –
Actually, you can’t read this value from the client.
Doing it from the server will either return the group id or player userid.

No, it’s made by me and not owned by any group.

Do it from the server, you can’t read if from the client because it’ll just return 0

Yes that’s what I’m doing, I’m getting the creatorId then passing it in a RemoteEvent:FireAllClients

Then what’s the issue now?
(char limit)

So what’s happening is that instead of putting the value I passed in the server, it’s just putting the value of ‘userRealName’ (which in my case I changed the value to ‘Not found’ and it’s putting that in the Gui)

From what i see, you want to get the name of the player, not the player object, that is why it returns 0 or “”, since the player does not exist,i think i the fixed code:

local players = game:GetService('Players')

local name = players:GetNameFromUserIdAsync(game.CreatorId)

script.Parent.argPass:FireAllClients(name, game.Name)

It still dosen’t work, just changes the Gui text to realUserName which is 'Not found;

You are trying to FireAllClients when the player isn’t in the game yet. So basically you do FireAllClients(), but no client registers it. I recommend you using a RemoteFunction which would be Invoked from client’s side and would return the owner name.

I made a little mistake in the script, I already edited the error, can you try again?

No I tried already with out the extra : and it didnt work

1 Like

Wait if I understand I want to pass it from the server to client, not client to server (never mind just figured out it had InvokeClient)

From what I see, the remote event is inside serverscriptservice, a place that localscripts cannot access, change the place of the remote event to replicated storage so the client / server can get access.

(i say this beacuse of the first script)

What I mean is something like this:

Client side:

local userRealName, realGameName = remoteFunction:InvokeServer()

ServerSide:

remoteFunction.OnServerInvoke = function()
    return name, game.Name
end

EDIT: It might actually be a better idea to store the game’s and owner’s name in a StringValue which would be stored somewhere in ReplicatedStorage

https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerByUserId

GetPlayerByUserId()

This function searches each player in Players for one whose Player.UserId matches the given UserId.

Won’t work as long as the owner of the game isn’t inside the server.

If the game isn’t published it will return the Templates account which hosts these templates.
https://www.roblox.com/users/998796/profile

Or if it’s saved in a file on your computer the CreatorId will return as 0.

Still dosent work:

Client:

local players = game:GetService('Players')
local startergui = game:GetService('StarterGui')

local argPass = game:GetService('ReplicatedStorage'):WaitForChild('5CLoaderAssets'):WaitForChild('argPass')
local bg = script.Parent:WaitForChild('bg')

local bar = bg:WaitForChild('bar_0').bar
local name = bg:WaitForChild('creator')
local gameName = bg:WaitForChild('game_name')
local shadow = bg:WaitForChild('shadow')

local userRealName, realGameName = argPass:InvokeServer()

argPass.OnClientInvoke:Connect(function(user_id, game_name)
	userRealName = user_id
	realGameName = game_name
end)

function loadAssets()
	name.Text = userRealName
	gameName.Text = realGameName
	shadow.Text = userRealName
end

loadAssets()

Server

local players = game:GetService('Players')

local name = players:GetNameFromUserIdAsync(game.CreatorId)

script.Parent.argPass.OnServerInvoke = function()
	return name, game.Name
end

Ok, I think i fixed your code, could you try it please?

Server:

local name = players:GetNameFromUserIdAsync(game.CreatorId)
local Remote = game:GetService('ReplicatedStorage'):WaitForChild('5CLoaderAssets'):FindFirstChild('argPass')

Remote:FireAllClients(name, game.Name)

Client:

local players = game:GetService('Players')
local startergui = game:GetService('StarterGui')

local argPass = game:GetService('ReplicatedStorage'):WaitForChild('5CLoaderAssets'):WaitForChild('argPass')
local bg = script.Parent:WaitForChild('bg')

local bar = bg:WaitForChild('bar_0').bar
local name = bg:WaitForChild('creator')
local gameName = bg:WaitForChild('game_name')

local userRealName = ''
local realGameName = ''

argPass.OnClientEvent:Connect(function(PlayerName, game_name)
	userRealName = PlayerName
	realGameName = game_name
end)

function loadAssets()
	name.Text = userRealName
	gameName.Text = realGameName
end

loadAssets()

To make this method work, you will have to replace the argPass remote event with a remote function object. Then the scripts would look like this:

Client:

local bar = bg:WaitForChild('bar_0').bar
local name = bg:WaitForChild('creator')
local gameName = bg:WaitForChild('game_name')
local shadow = bg:WaitForChild('shadow')

local userRealName, realGameName = argPass:InvokeServer()

function loadAssets()
	name.Text = userRealName
	gameName.Text = realGameName
	shadow.Text = userRealName
end

loadAssets()

Server:

local players = game:GetService('Players')

local name = players:GetNameFromUserIdAsync(game.CreatorId)

script.Parent.argPass.OnServerInvoke = function()
	return name, game.Name
end

You have to publish your game for the CreatorId to work.