You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Retrieve a random datastore and its data.
-
What is the issue? It returns nil or an error.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes. I looked and even posted.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
SERVER
local uniqueCode = ""
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local HttpsService = game:GetService("HttpService")
local DatastoreServive = game:GetService("DataStoreService")
local TextService = game:GetService("TextService")
--// Datasores
local Data_TotalAmount = DatastoreServive:GetDataStore("TotalAmountOfPosts")
local AllServers = DatastoreServive:GetDataStore("AllServersDS")
--// Objects
local Events = ReplicatedStorage:WaitForChild("Events")
local TotalVal = Instance.new("IntValue")
--// Events
local SendPost = Events:WaitForChild("SendPost")
local ChangeData = Events:WaitForChild("ChangeData")
local ClientToServer = Events:WaitForChild("SendFilterSignalToServer")
local ServerToClient = Events:WaitForChild("SendFilterSignalToClient")
local SendPostData = Events:WaitForChild("MakePostData")
local GenerateFeed = Events:WaitForChild("GenerateFeed")
--// Code
TotalVal.Value = 0
ClientToServer.OnServerEvent:Connect(function(Player, T, M)
local filtertedText = ""
local filteredMessage = ""
local success, errorMessage = pcall(function()
filtertedText = TextService:FilterStringAsync(T, Player.UserId)
print(tostring(filtertedText))
end)
if not success then
print(errorMessage)
end
local success2, errorMessage2 = pcall(function()
filteredMessage = TextService:FilterStringAsync(M, Player.UserId)
ServerToClient:FireClient(Player, filteredMessage, filtertedText)
print(filteredMessage)
end)
if not success2 then
print(errorMessage)
return
end
if success and success2 then
ServerToClient:FireClient(Player)
end
end)
MessagingService:SubscribeAsync("SendPost", function(messages)
messages = messages.Data
print(messages[1])
print(messages[2])
print(messages[3])
print(messages[4])
TotalVal.Value = TotalVal.Value +1
for _, player in pairs(Players:GetPlayers()) do
if player.PlayerGui.MainGui.MainFrame["Newest Posts"] then
local ClonedPost = player.PlayerGui.MainGui.MainFrame["Newest Posts"].Template
ClonedPost.Parent = player.PlayerGui.MainGui.MainFrame["Newest Posts"]
ClonedPost.Username.Text = "@"..messages[1]
ClonedPost.DisplayName.Text = messages[2]
ClonedPost.Message.Text = messages[4]
ClonedPost.Title.Text = messages[3]
local unique = HttpsService:GenerateGUID(false)
ClonedPost.UniquePostNumber.Text = unique
uniqueCode = unique
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size100x100
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local ProfilePic = ClonedPost.ProfilePicture
ProfilePic.Image = content
------------------------------
local success, errorMessage = pcall(function()
Data_TotalAmount:SetAsync("Key", TotalVal.Value)
end)
if not success then
print(errorMessage)
end
end
------------------------------
TotalVal.Value = TotalVal.Value +1
Data_TotalAmount:SetAsync("Key", TotalVal.Value)
end
end)
SendPost.OnServerEvent:Connect(function(Player:Player, A:TextBox, B)
MessagingService:PublishAsync("SendPost", {Player.Name, Player.DisplayName, Player.MessageString.Value, Player.TitleString.Value})
print(Player.Name)
print(Player.DisplayName)
end)
ChangeData.OnServerEvent:Connect(function(Player, T, M)
Player:WaitForChild("MessageString").Value = M
Player.TitleString.Value = T
warn("Running V1 Of Change Data")
end)
local ds = game:GetService("DataStoreService"):GetDataStore("GlobalValue")
local SERVER_KEY_NAME = "Server"
local success, data = pcall(function()
return ds:GetAsync(SERVER_KEY_NAME)
end)
ds:SetAsync(SERVER_KEY_NAME, TotalVal.Value)
wait(4)
if success then
print(data) -->> the server data
for i, v in pairs(Players:GetPlayers()) do
v.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "..tostring(data)
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "tostring(data)
end)
TotalVal:GetPropertyChangedSignal("Value"):Connect(function()
TotalVal.Value = TotalVal.Value -1
ds:SetAsync(SERVER_KEY_NAME, TotalVal.Value)
wait(4)
for i, v in pairs(Players:GetPlayers()) do
v.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "..tostring(TotalVal.Value)
end
end)
SendPostData.OnServerEvent:Connect(function(Player, FilteredMsg, FilteredTitle)
local userId = Player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size60x60
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local tab = {
message = "success",
info = {
Message = FilteredMsg,
Title = FilteredTitle,
PlayerName = Player.Name,
PlayerDisplay = Player.DisplayName,
ProfilePicture = content,
UniqueCode = uniqueCode,
}
}
warn(uniqueCode)
local json = HttpsService:JSONEncode(tab)
print(json)
uniqueCode = tab.info.UniqueCode
AllServers:SetAsync(uniqueCode)
print(json)
local findData = AllServers:GetAsync(tab.info.UniqueCode)
print(findData)
end)
GenerateFeed.OnServerEvent:Connect(function(Player)
local function getKeys(datastore)
local keys = {}
local keyPages = datastore:ListKeysAsync();
if keyPages then
repeat
local keyP = keyPages:GetCurrentPage()
for _,k in keyP do
table.insert(keys,k.KeyName)
end
keyPages:AdvanceToNextPageAsync()
task.wait()
until
keyPages.IsFinished
print(keys)
end
return keys
end
local dataKeys = getKeys(AllServers);
print(uniqueCode.." given code!")
foundData = AllServers:GetAsync(uniqueCode)
print(foundData)
uniqueCode = ""
end)
CLIENT
local vNumber = "1.1"
local OkToPost = false
warn("Running version "..vNumber.." for RoFeed. Current game name for refrence: "..game.Name..". DevKeia's property!")
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local TweenService = game:GetService("TweenService")
local TextService = game:GetService("TextService")
local Chat = game:GetService("Chat")
local InfoTween = TweenInfo.new(0.7, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
--// Events
local SendPost = Events:WaitForChild("SendPost")
local ChangeData = Events:WaitForChild("ChangeData")
local SendSignalToServerPost = Events:WaitForChild("SendFilterSignalToServer")
local SendFilterSignalToClient = Events:WaitForChild("SendFilterSignalToClient")
local SendPostData = Events:WaitForChild("MakePostData")
local GenerateFeed = Events:WaitForChild("GenerateFeed")
--// Objects
local MainGui = script.Parent
local MainFrame = MainGui:WaitForChild("MainFrame")
local NotificationFrame = script.Parent.Notification
local PostTitle = MainFrame:WaitForChild("PostTitle")
local PostMessage = MainFrame:WaitForChild("PostMessage")
local PostButton = MainFrame:WaitForChild("PostButton")
local LoadingFrame = script.Parent.Loading
local LoadingNotice = LoadingFrame:WaitForChild("Notice")
LoadingFrame.Visible = true
task.wait(0.5)
LoadingNotice.Text = "Sending Data!"
task.wait(0.5)
LoadingNotice.Text = "Gathering your posts!"
task.wait(1)
LoadingNotice.Text = "Checking the feeds."
task.wait(0.5)
LoadingNotice.Text = "Sending 'Messaging Service' signal!"
task.wait(0.5)
LoadingNotice.Text = "Checking for ReplicatedStorage events..."
task.wait(1)
LoadingNotice.Text = "Loading GUI..."
task.wait(0.5)
LoadingNotice.Text = "Done!"
LoadingFrame:TweenPosition(UDim2.new(0, 0,0, 850))
--// Code
SendFilterSignalToClient.OnClientEvent:Connect(function(M:TextFilterResult, T:TextFilterResult)
OkToPost = true
PostMessage.Text = M
PostTitle.Text = T
end)
PostButton.MouseButton1Click:Connect(function()
if PostTitle.Text ~= "TITLE:" then
if PostMessage.Text ~= "WHAT DO YOU WANT TO TELL THE WORLD?" then
SendSignalToServerPost:FireServer(PostTitle.Text, PostMessage.Text)
wait(0.2)
local filteredMessage = Chat:FilterStringForBroadcast(PostMessage.Text, game.Players.LocalPlayer)
local filteredTitle = Chat:FilterStringForBroadcast(PostTitle.Text, game.Players.LocalPlayer)
SendFilterSignalToClient.OnClientEvent:Connect(function()
OkToPost = true
end)
wait(0.1)
if OkToPost == true then
NotificationFrame.Visible = true
NotificationFrame.Note.Text = "Sending your data to the server..."
ChangeData:FireServer(filteredMessage, filteredTitle)
wait(0.3)
NotificationFrame.Note.Text = "Sending the post along all servers..."
SendPost:FireServer(filteredTitle, filteredMessage)
NotificationFrame.Note.Text = "Posting..."
wait(0.3)
NotificationFrame.Note.Text = "Done!"
wait(0.3)
NotificationFrame.Note.Text = "Adding your post to current Datastore."
wait(1.5)
NotificationFrame.Visible = false
warn("Sucessfully ran V1 of Publishing Messaging Service for RoFeed")
SendPostData:FireServer(filteredMessage, filteredTitle)
elseif OkToPost == false then
NotificationFrame.Note.Text = "Your post couldn't be filtered. Please only post appropriate posts!"
wait(1.5)
NotificationFrame.Visible = false
end
end
end
end)
GenerateFeed:FireServer()
OUTPUT
