✓ 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
11 comments
what do you mean by get whether they are online or offline --- where would you want the message to appear? / what purpose?
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?
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?
just once after they join the game. want to check the player's data with it with a plugin.
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
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
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
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.
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
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
oh ok got it.