Hello there, I have Forum post in here two times with same goal as this post, but No actual help has Arrived to help me, I have used Multiple ChatGPT AI script generations in attempt of fixing the script by myself, but I had no luck with that… my second forum post literally had no replies in the topic, I wanted to make this youtuber named Siwon’s how to make game like Sol’s RNG Part 2 ( Link to the Video by Siwon because I wanted to make an Sol’s RNG like game by myself, but he has only made Part 1 and Part 2 so far, and it lacks scripts which allows it to save and load the Inventory and Rolls…
as I have said prior to this texts, I have used multiple ChatGPT’s AI LUA script generating skills to Fix the problem or the what Siwon’s Scripts lacked for right now by myself… but it only made the Script even more worse and non-functioning…
here is Result of AI generated scripts so far, I have no idea what this exactly does, but when I put this script into my main handler script in the ServerScriptService , it just doesn’t save the Data of Player at all or have Errors and warns on the output issuing the script errors caused by ChatGPT…
I will send the almost every attempt of Fixing the script in this post, including ChatGPT conversations, Rbxl file of Test Experience/Game which has other LocalScript and ModuleScripts that makes the ServerScriptService Script work with these…
--AI generated "Fixed Script"... Has something confusing with Line 77 ~ Line 108 ...
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RollEvent = ReplicatedStorage:WaitForChild("RollEvent")
local Chances = require(ReplicatedStorage:WaitForChild("Chances"))
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
local SelectRNG = require(ReplicatedStorage:WaitForChild("SelectRNG"))
local function SavePlayerData(userId, inventory, rolls)
local saveData = {
Inventory = inventory,
Rolls = rolls
}
local success, err = pcall(function()
playerDataStore:SetAsync("PlayerData"..userId, saveData)
end)
if not success then
warn("Failed to save data for player "..userId..": "..err)
end
end
local function LoadPlayerData(userId)
local success, data = pcall(playerDataStore.GetAsync, playerDataStore, "PlayerData"..userId)
if success and data then
return data.Inventory, data.Rolls
else
warn("Failed to load data for player "..userId)
return nil, 0
end
end
local function PlayerJoined(player)
local userId = player.UserId
local inventory, rolls = LoadPlayerData(userId)
if not inventory then
inventory = {
Limit = 10,
LatestRoll = nil,
Equipped = nil,
Backpack = {}
}
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local rollsValue = Instance.new("IntValue")
rollsValue.Name = "Rolls"
rollsValue.Value = rolls
rollsValue.Parent = leaderstats
SavePlayerData(userId, inventory, rolls)
end
local function PlayerLeft(player)
local userId = player.UserId
local inventory, rolls = LoadPlayerData(userId)
if inventory then
SavePlayerData(userId, inventory, player.leaderstats.Rolls.Value)
else
warn("Failed to save data for player "..userId..": Inventory data not found.")
end
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
local SelectRNG = require(ReplicatedStorage:WaitForChild("SelectRNG"))
local function HandleRollEvent(player, header)
local userId = player.UserId
local inventory, rolls = LoadPlayerData(userId)
if header == "Get" then
local UserInventory = inventory[player.UserId]
local UserLimit = UserInventory["Limit"]
local Backpack = UserInventory["Backpack"]
if #Backpack >= UserLimit then
table.remove(Backpack, table.find(Backpack, inventory.Equipped) or UserLimit)
end
table.insert(Backpack, UserInventory["LatestRoll"])
elseif header == "Waste" then
inventory.LatestRoll = nil
elseif header == "GetInventory" then
return inventory.Backpack
else
local Result = Chances[SelectRNG(player)][1]
inventory.LatestRoll = Result
return Result
end
print(inventory.Backpack)
return
end
RollEvent.OnServerInvoke = HandleRollEvent
--Script before it gets some additional changes with ChatGPT AI... :<
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RollEvent = ReplicatedStorage:WaitForChild("RollEvent")
local Chances = require(ReplicatedStorage:WaitForChild("Chances"))
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
local Inventory = {}
-- Function to save player data to DataStore
local function SavePlayerData(User)
local userId = User.UserId
local success, err = pcall(function()
local rolls = User:FindFirstChild("leaderstats"):FindFirstChild("Rolls").Value
local saveData = {Inventory = Inventory[userId], Rolls = rolls}
-- Update the existing data in the DataStore instead of overwriting it
local existingData = playerDataStore:GetAsync("PlayerData"..userId) or {}
for key, value in pairs(saveData) do
existingData[key] = value
end
playerDataStore:SetAsync("PlayerData"..userId, existingData)
end)
if not success then
warn("Failed to save data for player "..userId..": "..err)
end
end
-- Function to handle player join
local function PlayerJoined(User)
-- Step 1: Create the leaderstats folder and parent it to the User
local LeaderStats = Instance.new("Folder", User)
LeaderStats.Name = "leaderstats"
-- Step 2: Create the Rolls IntValue inside the leaderstats folder
local Rolls = Instance.new("IntValue", LeaderStats)
Rolls.Name = "Rolls"
-- Attempt to load the player's data
local userId = User.UserId
local success, data = pcall(function()
return playerDataStore:GetAsync("PlayerData"..userId)
end)
-- Handle the retrieved or default data
if success then
if data then
Inventory[userId] = data.Inventory or {
Limit = 10,
LatestRoll = nil,
Equipped = nil,
Backpack = {}
}
-- Load the Rolls value
local rollsValue = data.Rolls or 0
Rolls.Value = rollsValue
else
Inventory[userId] = {
Limit = 10,
LatestRoll = nil,
Equipped = nil,
Backpack = {}
}
Rolls.Value = 0 -- Default Rolls value if no data is found
end
else
-- Log an error if data retrieval failed
warn("Failed to load data for player "..userId)
end
end
-- Function to handle player leaving
local function PlayerLeft(User)
SavePlayerData(User)
end
-- Connect events
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
local SelectRNG = require(ReplicatedStorage:WaitForChild("SelectRNG"))
RollEvent.OnServerInvoke = function(User, Header)
local UserInventory = Inventory[User.UserId]
local UserLimit = UserInventory["Limit"]
local Backpack = UserInventory["Backpack"]
if Header == "Get" then
if #Backpack >= UserLimit then
table.remove(Backpack, table.find(Backpack, UserInventory["Equipped"]) or UserLimit)
end
table.insert(Backpack, UserInventory["LastestRoll"])
elseif Header == "Waste" then
UserInventory["LastestRoll"] = nil
elseif Header == "GetInventory" then
return Backpack
else
local Result = Chances[SelectRNG(User)][1]
UserInventory["LastestRoll"] = Result
return Result
end
print(Backpack)
return
end
I have tried my best to make my own scripts by myself… but I literally suck at it that I am unable to make an functioning script by myself alone… I am able to Donate to the Developer ~70RS (or maybe bit more if you do ask me to) who were able to Fix the Errors in the script to make it so the script saves and loads the Data of the Game properly… I am this desperate to Fix this Main ServerScriptService Script… but peoples Keep on Ignoring me, I have also posted about this issue on the Roblox Studio Community Discord Server, but I had no visitors to my Topic Post…
I will also post this Rbxl file of the test game I have made… feel free to manually check the game and enable HTTP requests in the test game and the Enable Studio Access to API so you could actually test the game and find the errors…
SolsRNGLikeGameTest1(Does not have the New AI script codes).rbxl (72.2 KB)
thank you so much for reading my Topic Post, I know that has taken you much efforts to read all of it, I honestly want this Script to get Fixed soon so I can actually make the Game inspired by Sol’s RNG… - Mari