You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I am trying to make a data store that saves a player’s clothing. -
What is the issue? Include screenshots / videos if possible!
I don’t know why but the script breaks when I try assigning the data to something. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried searching up a solution but I couldn’t find anything.
local DataStoreService = game:GetService("DataStoreService")
local player_data = DataStoreService:GetDataStore("Player_Data")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "Leaderstats"
leaderstats.Parent = player
local playerUserID = "Player_"..player.UserId
local data
local success, errorMessage = pcall(function()
data = player_data:GetAsync(playerUserID)
end)
if success then
print("There is data") -- breaks in the line after this
player.PlayerGui:FindFirstChild("new_Catalog").Save_see.Folder.pant_1.Value = data
else
print("no data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = "Player_"..player.UserId
local Data = player.Leaderstats.Pants_1.Value
local success, errormessage = pcall(function()
player_data:SetAsync(playerUserID, Data)
end)
if success then
print("saved")
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.