Hello! I was wondering how I can get the game creator’s username. Currently, I only found out
game.CreatorId
but I was wondering if there is something like game.CreatorName
. Help is greatly appreciated!
You could do that by using game.CreatorId
. (let me show you how!)
local creatorName = game.Players:GetPlayerByUserId(game.CreatorId)
But, the creator would have to be playing the game. My code won’t work in some cases, but it was the only thing I could think of.
I don’t know if game.Parent
will give you the player’s name?
I have tried that around 2 weeks ago. I will just wait and see if someone replies with a different answer. Thanks for your contribution though!
@IAmPinleon I have tried game.Parent
and I can confirm it does not work.
That was actually a great idea though!
This code should give you the creator’s name.
local players = game:GetService("Players")
local function GetCreatorName()
if game.CreatorType == Enum.CreatorType.User then --Check if they are a user
return players:GetNameFromUserIdAsync(game.CreatorId)
end
end
You can use Players::GetNameFromUserIdAsync
to get a name from a given user ID.
However, game.CreatorId
if the game is a group game, will give you the group ID instead.
So you can do GroupService:GetGroupInfoAsync(game.CreatorId).Owner
to get the name of the owner of the group
Would I be able to improve that code using an elseif
for a group using @sjr04’s other code?
You can actually just use an else
rather than an elseif
, but yes would be able to improve it.
Hi, @IAmPinleon,
I’ve tried with that and it only returns a Instance
, that is the given player with the userId.
If that player with that ID is not playing, it will return nil
.
You can try with this (this works btw):
`local creatorName = game.Players:GetNameFromUserIdAsync(game.CreatorId)`
And yes, it prints the creator name.
For suggestions or questions of this post, message me.