-
What do you want to achieve? Keep it simple and clear!
Successfully get the tools a player has when he/she leaves then joins, DataStore. - What is the issue? Include screenshots / videos if possible!
local DSS = game:GetService("DataStoreService")
local myToolDSS = DSS:GetDataStore("myToolDSS")
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errormessage = pcall(function()
data = myToolDSS:GetAsync(player.UserId.."-tools")
end)
if success then
print(data)
else
print("There was an error whilst getting your data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
getToolsEvent.OnServerEvent:Connect(function(player, myTools)
local ownedTools = myTools.Value
print(ownedTools)
myToolDSS:SetAsync(player.UserId.."-tools", ownedTools.Value)
end)
end)
if success then
print("Data successfully saved!")
else
print("There was an error saving your data.")
warn(errormessage)
end
end)
What the output looks like after printing
I made it as a table so that multiple tools can be saved. Can anyone set a base idea for me? My goal is to just get the tools (values which represent the names) when a player joins. I am not requesting for a whole script, just an idea and probably some minor scripting mistakes I had missed.