Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Getting names of player who played your game?

> THIS QUESTION MIGHT NOT BE RELATED TO ROBLOX SCRIPTING!

I was wondering if it was possible to get the name of the player who had played your game and save it? Let's say you have a game and 1,000 player plays it and which 500 of the players are offline. Can you get the names of the players who are offline and online? and if so, how? Couldn't think of a way to do it. Any help or tips would be great!

want to get their name/ id of the player so that I can check their data using this plugin and the video to it

11 comments

0

what do you mean by get whether they are online or offline --- where would you want the message to appear? / what purpose?

0

ok let's say there is two player playing a game, their id are "123456789" and "987654321", when they join the game, the server script picks it up and save the id/ names of the player in an external website or app [excel or google doc]. Is it possible to do it?

0

yes, you can save the id numbers to a separate site, I can show an example if that's what you're looking for, would you want it to occur once, or everytime they start playing?

0

just once after they join the game. want to check the player's data with it with a plugin.

0

as in the first time they join the game? or everytime they join? also looking at the video, the user says to enable studio access to api, though this has been shown to sometimes cause some errors with the datastore

0

but isnt it a must to enable studio access api to make datastore work? if it is possible, it will check the player id/name on the site and if it doesnt exist then it will make a new one for the player

0

enable studio api access is needed to make a datastore work within studio, yes, but it can sometimes break the datastore in game because the value you save when testing is different than in an actual server, and ok, got it

0

still not fully sure how a datastore works but if i dont enable studio api access in game or in studio, it throws and error saying " studio api access must be enable for datastore to work" and i dont see how it might break the datastore if it is needed to make a datastore work.

0

it wont break in studio, it will break in the actual game, since the values would be inconsistent, that's why you enable studio access during testing, but turn it off when you make the game public

0

i'm not sure how that plug-in works exactly, at least since you'll want access off, but i'll give you a variation using discord

0

oh ok got it.

1 answer

✓ Accepted answer
local HTTP = game:GetService("HttpService")
local DSS = game:GetService("DataStoreService")
local Storage = DSS:GetDataStore("BasicInfo")
local webhook = "https://discordapp.com/api/webhooks/0"

game.Players.PlayerAdded:Connect(function(player)
	local newdata = Instance.new("BoolValue")
	newdata.Name = "HasPlayed"
	newdata.Value = false
	
	local success, result = pcall(function()
		Storage:GetAsync(player.UserId)
	end)
	
	if success then
		newdata.Value = Storage:GetAsync(player.UserId)
	else
		warn(result)
	end
	
	if not Storage:GetAsync(player.UserId) then
		newdata.Value = true
		local msg = "Joined the Game"
		local payload = HTTP:JSONEncode({content = msg, username = player.Name.." - (#"..player.UserId..")"})
		HTTP:PostAsync(webhook, payload)
		print("Complete")
		Storage:SetAsync(player.UserId, newdata.Value)
		print("Saved")
	end
end)

Make sure that Https Services are enabled through Studio --> Home --> Game Settings

For a Discord Server, you would add a webhook, then copy its link to the above variable "webhook".

Whenever a player joins the game, it will send the message that they joined (only if they don't have any datastore contents)

PCall is to prevent errors from occurring

You can also change "msg" to be a list (string) of the player's data if you wanted to

1 comment

0

Thanks it works like a charm :D

This discussion is preserved as it was. New answers, comments, and votes are closed.