Getting data from a datastore

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m working on a moderation system for my game and I made a datastore system for all the moderator actions and now I want to be able to get the all the actions that have been taken on a user and display the data I saved on a GUI

  2. What is the issue? It just doesnt work at all and with how this script currently is it even gives me an error attempt to concatenate string with Instance

This is the script that I made and it’s a server script.

local DS = game:GetService("DataStoreService"):GetDataStore("DS_modLog2", "Warnings")
local Players = game:GetService("Players")

game:GetService("ReplicatedStorage").GetData.OnServerEvent:Connect(function(UserID)
	local key = "Log_"..UserID
	local playerMod
	local success, err = pcall(function()
		playerMod = DS:GetAsync(key)
	end)
	
	for rank, data in ipairs(playerMod) do
		local c = script.Parent.ScrollingFrame.Template.Log:Clone()
		c.Reason.Text = data[4]
		c.Moderator.Text = "Issued by: "..data[2].."("..data[3]..")"
		c.Avatar.Image  = "rbxthumb://type=AvatarHeadShot&id="..data[3]:GetUserIdFromNameAsync(script.Parent.Input.Text).."&w=352&h=352 true false"
		c.Parent = script.Parent.ScrollingFrame
		c.Visible = true
	end
end)

Player is always returned first so you can tell what Client fired the Remote, you would have to make “UserID” a Second Return Value.

Using Player for gathering UserId:

game:GetService("ReplicatedStorage").GetData.OnServerEvent:Connect(function(Player)
	local key = "Log_".. Player.UserId

Using a Second Return Value:

game:GetService("ReplicatedStorage").GetData.OnServerEvent:Connect(function(Player, UserId)
	local key = "Log_".. UserId

Before you set the key variable, try priinting the userId. To see if it is being sent or not. You cannot concaconate strings with nil values.

Thanks for your help because of the print I realised that the first argument to “.OnServerEvent” is the client from which the event was triggered, but I didn’t want to put the ID of the guy who triggered it, but the ID of the person I put in the remote event, so that was just my mistake as to why it didn’t work at all.

Your welcome! :wink: I hope you become a great scripter in the future!