Award Player an Item when they join the game during an event, item saves for when the player joins back

Hey developers,

I’m fixing up my game for a new update when I realized I was going to do an event for them. I want it so when the player joins the game, it will create a value that will be stored in the player.

Once that has been created, it will check a datastore to see if they player has already joined during the event, which will be toggled on if the player did join during the event.

I’m having a problem where I need it to check if the player has joined during the event, but I have no clue on how I would make that happen. Would anyone so far help me with this script?

--// Variables
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("RWE_Awarded1K")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Gears = ReplicatedStorage:WaitForChild("Gears")
local Clean1k = Gears["1K Clean"]

--// Functions
local function awardClean()
	
end

--// Script
game:GetService("Players").PlayerAdded:Connect(function(player)	
	local JDE = Instance.new("BoolValue")
	JDE.Name = "Has1kClean"
	JDE.Parent = player
	
	local DownloadedData = DS:GetAsync(tostring(player.UserId))
	local Response, Success = pcall(function()
		return DownloadedData
	end)
	
	if Success then
		
	end
end)

Hye!

Your script attempts to check if a player has already received the item using a DataStore, but it’s missing the logic to properly retrieve and save that data!

Keep in mind that the script I made isn’t fully completed as you should learn by code and not directly copy and paste. You’ll have to adjust some variables by yourself to your likings.

-- Let's start of by completing your function awardClean()
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local function awardClean(player)
	if not Clean1k then return end
	
	local itemCopy = Clean1k:Clone()
	itemCopy.Parent = player.Backpack
end

-- PlayerAdded Event

Players.PlayerAdded:Connect(function(player)
	local JDE = Instance.new("BoolValue")
	JDE.Name = "Has1kClean"
	JDE.Parent = player
	
	local success, data = pcall(function()
		return DataStoreService:GetAsync(tostring(player.UserId))
	end)
	
	if success and data then
		JDE.Value = true
	else
		awardClean(player)
		JDE.Value = true
		
		pcall(function()
			DataStoreService:SetAsync(tostring(player.UserId), true)
		end)
	end
end)

Please let me know if the issue persists, and I will be happy to assist you further.