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.
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)
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.
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.
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