so a new scripter came in and changed the datastore but now hes in the military. now there is a datafolder that looks lke this: how do I fix the quests datastore?
–!strict
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local SharedTypes = require(ReplicatedStorage.Types)
type DataFolder = SharedTypes.DataFolder
local Player: Player = Players.LocalPlayer
local DataFolder: DataFolder = Player:WaitForChild(“Data”) :: DataFolder
local update = game.ReplicatedStorage.events.UpdatePlayerData
local profiles = require(game.ServerStorage:WaitForChild("PlayerData"):WaitForChild("manager")).Profiles
script.Parent.mainRE.OnServerEvent:Connect(function(plr, arg, na)
-- Get the player's profile
local profile = profiles[plr]
if not profile then
warn("Profile not found for player:", plr.Name)
return
end
-- Get or create the DataFolder
local dataFolder = plr:FindFirstChild("DataFolder")
if not dataFolder then
warn("DataFolder not found for player:", plr.Name)
return
end
-- Handle different arguments
if arg == "addLVL" then
local level = dataFolder:FindFirstChild("Level")
if level then
level.Value += na
profile.Data.Data.Level += na
update:Fire()
else
warn("Level value not found in DataFolder for player:", plr.Name)
end
elseif arg == "addEXP" then
local experience = dataFolder:FindFirstChild("Experience")
if experience then
experience.Value += na
profile.Data.Data.Experience += na
update:Fire()
else
warn("Experience value not found in DataFolder for player:", plr.Name)
end
elseif arg == "addCoins" then
local money = dataFolder:FindFirstChild("Money")
if money then
money.Value += na
profile.Data.Data.Money += na
update:Fire()
else
warn("Money value not found in DataFolder for player:", plr.Name)
end
elseif arg == "setVal" then
local questNum = dataFolder:FindFirstChild("QuestNum")
if questNum then
questNum.Value = na
else
warn("QuestNum value not found in DataFolder for player:", plr.Name)
end
end
end)
You can start by describing more of the problem. The only thing I know is that the “quests datastore” is broken somewhere, but without any other context, I’d be hard pressed to find where it’s broken. Here are a couple of questions to help you get started:
What is supposed to happen? What is the script supposed to do?
What did the guy change? Was it working before and if yes, did you try to revert to that previous version?
How does this system work (I can probably guess from reading, but it’d be faster for both you and I if I didn’t)?
So the issue is that everytime I join the game, there is no quest saving because the new scripter made a datafolder that I don’t know how to connect this code.
This is the datastore:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local SharedTypes = require(ReplicatedStorage.Types)
type DataFolder = SharedTypes.DataFolder
local dss = DataStoreService:GetDataStore("uh")
-- Function to generate a unique key for saving/loading data
function getKey(plr: Player): string
return tostring(plr.UserId) .. "-growyourslimes"
end
-- Function to save player data
function save(plr: Player)
local success, err = pcall(function()
local dataFolder = plr:FindFirstChild("Data") :: DataFolder
if dataFolder then
local questNum = dataFolder:FindFirstChild("QuestNum") :: NumberValue
if questNum then
dss:SetAsync(getKey(plr), questNum.Value)
end
end
end)
if success then
print("SAVED QUEST for player:", plr.Name)
else
warn("Failed to save data for player:", plr.Name, err)
end
end
-- Function to load player data
function load(plr: Player): number?
local data
local success, err = pcall(function()
data = dss:GetAsync(getKey(plr))
end)
if success then
print("LOADED QUEST for player:", plr.Name)
else
warn("Failed to load data for player:", plr.Name, err)
end
return data
end
-- PlayerAdded handler
game.Players.PlayerAdded:Connect(function(plr)
-- Wait for the player's DataFolder to exist
local dataFolder = plr:WaitForChild("Data") :: DataFolder
-- Ensure QuestNum exists in DataFolder
local questNum = dataFolder:FindFirstChild("QuestNum") :: NumberValue
if not questNum then
questNum = Instance.new("NumberValue")
questNum.Name = "QuestNum"
questNum.Value = 1
questNum.Parent = dataFolder
end
-- Load saved data
local savedData = load(plr)
if savedData ~= nil then
questNum.Value = savedData
else
questNum.Value = 1
end
-- Fire client events based on quest data
if questNum.Value == 1 then
ReplicatedStorage.events.requestBeginnerTrail:FireClient(plr)
end
ReplicatedStorage.events.setupQuest:FireClient(plr, questNum.Value)
end)
-- Save data when players leave
game.Players.PlayerRemoving:Connect(function(plr)
save(plr)
end)
-- Save all data when the game closes
game:BindToClose(function()
for _, plr in ipairs(Players:GetPlayers()) do
save(plr)
end
end)
This script is called questhandlerserver under questHandler which handles all the quests (theres no issues with that script so I wont send it)
local update = game.ReplicatedStorage.events.UpdatePlayerData
local profiles = require(game.ServerStorage:WaitForChild("PlayerData"):WaitForChild("manager")).Profiles
script.Parent.mainRE.OnServerEvent:Connect(function(plr, arg, na)
-- Get the player's profile
local profile = profiles[plr]
if not profile then
warn("Profile not found for player:", plr.Name)
return
end
-- Get or create the DataFolder
local dataFolder = plr:FindFirstChild("DataFolder")
if not dataFolder then
warn("DataFolder not found for player:", plr.Name)
return
end
-- Handle different arguments
if arg == "addLVL" then
local level = dataFolder:FindFirstChild("Level")
if level then
level.Value += na
profile.Data.Data.Level += na
update:Fire()
else
warn("Level value not found in DataFolder for player:", plr.Name)
end
elseif arg == "addEXP" then
local experience = dataFolder:FindFirstChild("Experience")
if experience then
experience.Value += na
profile.Data.Data.Experience += na
update:Fire()
else
warn("Experience value not found in DataFolder for player:", plr.Name)
end
elseif arg == "addCoins" then
local money = dataFolder:FindFirstChild("Money")
if money then
money.Value += na
profile.Data.Data.Money += na
update:Fire()
else
warn("Money value not found in DataFolder for player:", plr.Name)
end
elseif arg == "setVal" then
local questNum = dataFolder:FindFirstChild("QuestNum")
if questNum then
questNum.Value = na
else
warn("QuestNum value not found in DataFolder for player:", plr.Name)
end
end
end)
I can’t summon the scripting knowledge into your brain I’m telling you, profile service is easier. And I sent you a good tutorial video telling you exactly what to do and how it works