When I try to place the plank, this pops up:
Oh, easy fix just put duplicate the remote event called “UnlockEvent” and put it in replicated storage
I hate to do this but 1 final revision of code for the DataStore script in ServerScriptService here:
local DataModule = require(game.ReplicatedStorage.DataStoreModule)
local DSS = game:GetService("DataStoreService")
local PlayerDataStore = DSS:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(Player)
local Success, Data = pcall(function()
return PlayerDataStore:GetAsync(Player.UserId)
end)
warn("Success:", Success)
warn("Data:", Data)
if Success and Data then
DataModule.SetPlayerData(Player.Name, Data)
elseif Success and not Data then
warn("Unable to get "..Player.Name.."'s data, they are a new player!")
DataModule.SetPlayerDataDefault(Player.Name)
elseif not Success and not Data then
Player:Kick("Error while connecting to roblox datastore, please rejoin or try again later.")
error("Unable to get "..Player.Name.."'s data, unable to connect to datastores.")
end
for i, v in pairs(Data) do
if workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i) ~= nil then
if v == true then
Player.PlayerScripts:WaitForChild("UnlockEvent"):FireClient(Player, workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i))
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local PlayerData = DataModule.RequestPlayerData(Player.Name)
if PlayerData ~= nil then
warn("Saving "..Player.Name.."'s Player data as", PlayerData)
local Success, ErrorCode = pcall(function()
PlayerDataStore:SetAsync(Player.UserId, PlayerData)
end)
if not Success then
warn(ErrorCode)
else
local Success, Data = pcall(function()
PlayerDataStore:GetAsync(Player.UserId)
end)
warn(Data)
end
end
end)
Thank you so so much for this help, I do have a question. I placed a plank and rejoin and it did not save. Is there a specific time to wait inbetween for it to save? I did only test it in studio, does it only work in game?
If you publish the game, ill test it out and give it a go, also if it prints the data when someone joins please can I see it?
Make sure API is enabled in security.
Alright, I just published the game.
if Data ~= nil then
for i, v in pairs(Data) do
if workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i) ~= nil then
if v == true then
Player.PlayerScripts:WaitForChild("UnlockEvent"):FireClient(Player, workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i))
end
end
end
end
new serverscriptservice data store script
replace that with the old pairs thing
local DataModule = require(game.ReplicatedStorage.DataStoreModule)
local DSS = game:GetService("DataStoreService")
local PlayerDataStore = DSS:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(Player)
local Success, Data = pcall(function()
return PlayerDataStore:GetAsync(Player.UserId)
end)
warn("Success:", Success)
warn("Data:", Data)
if Success and Data then
DataModule.SetPlayerData(Player.Name, Data)
elseif Success and not Data then
warn("Unable to get "..Player.Name.."'s data, they are a new player!")
DataModule.SetPlayerDataDefault(Player.Name)
elseif not Success and not Data then
Player:Kick("Error while connecting to roblox datastore, please rejoin or try again later.")
error("Unable to get "..Player.Name.."'s data, unable to connect to datastores.")
end
if Data ~= nil then
for i, v in pairs(Data) do
if workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i) ~= nil then
if v == true then
Player.PlayerScripts:WaitForChild("UnlockEvent"):FireClient(Player, workspace:FindFirstChild("ItemNeeded"):FindFirstChild(i))
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local PlayerData = DataModule.RequestPlayerData(Player.Name)
if PlayerData ~= nil then
warn("Saving "..Player.Name.."'s Player data as", PlayerData)
local Success, ErrorCode = pcall(function()
PlayerDataStore:SetAsync(Player.UserId, PlayerData)
end)
if not Success then
warn(ErrorCode)
else
local Success, Data = pcall(function()
PlayerDataStore:GetAsync(Player.UserId)
end)
warn(Data)
end
end
end)
here is the new
I figured a way to do, thank you so much for the help and everything!
Oh I’m glad I could help, did you use my datastore system or something else? I just tested the game and it works, nice!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.