local DataStoreService = game:GetService("DataStoreService") local Players =…
- User
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WalkSpeedStore = DataStoreService:GetDataStore("WalkSpeedDataStore") local CashStore = DataStoreService:GetDataStore("CashDataStore") local RebirthStore = DataStoreService:GetDataStore("RebirthDataStore")
local MAX_SPEED = 9e99 local GROUP_ID = 36035362 local INCREMENT_NON_GROUP = 0.05 local INCREMENT_GROUP = 0.1 local OFFLINE_INCREMENT = 1 / 200 local BASE_REBIRTH_COST = 10000
local offlineGainValue = ReplicatedStorage:FindFirstChild("OfflineGain") if not offlineGainValue then offlineGainValue = Instance.new("NumberValue") offlineGainValue.Name = "OfflineGain" offlineGainValue.Value = 0 offlineGainValue.Parent = ReplicatedStorage end
local rebirthEvent = Instance.new("RemoteEvent") rebirthEvent.Name = "RebirthEvent" rebirthEvent.Parent = ReplicatedStorage
local function applyDiminishingReturn(current, gain) local distance = MAX_SPEED - current if distance <= 0 then return 0 end return gain * (distance / MAX_SPEED) end
local function loadSpeed(player) local data local success = pcall(function() data = WalkSpeedStore:GetAsync(player.UserId) end) if success and data then return data.Speed or 0.00, data.LastLogout or os.time() else return 0.00, os.time() end end
local function saveSpeed(player, speed) pcall(function() WalkSpeedStore:SetAsync(player.UserId, {Speed = speed, LastLogout = os.time()}) end) end
local function loadCash(player) local cash local success = pcall(function() cash = CashStore:GetAsync(player.UserId) end) if success and cash then return cash else return 0 end end
local function saveCash(player, cash) pcall(function() CashStore:SetAsync(player.UserId, cash) end) end
local function loadRebirths(player) local rebirths local success = pcall(function() rebirths = RebirthStore:GetAsync(player.UserId) end) if success and rebirths then return rebirths else return 0 end end
local function saveRebirths(player, rebirths) pcall(function() RebirthStore:SetAsync(player.UserId, rebirths) end) end
Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local WalkSpeedValue = Instance.new("NumberValue") WalkSpeedValue.Name = "WalkSpeed" WalkSpeedValue.Parent = leaderstats local Cash = Instance.new("NumberValue") Cash.Name = "Cash" Cash.Value = loadCash(player) Cash.Parent = leaderstats local Rebirths = Instance.new("IntValue") Rebirths.Name = "Rebirths" Rebirths.Value = loadRebirths(player) Rebirths.Parent = leaderstats local storedSpeed, lastLogout = loadSpeed(player) local now = os.time() local offlineTime = now - lastLogout local inGroup = false pcall(function() inGroup = player:IsInGroup(GROUP_ID) end) local offlineGain = offlineTime * OFFLINE_INCREMENT * (inGroup and 2 or 1) local adjustedOfflineGain = applyDiminishingReturn(storedSpeed, offlineGain) storedSpeed = storedSpeed + adjustedOfflineGain WalkSpeedValue.Value = storedSpeed offlineGainValue.Value = math.max(0, adjustedOfflineGain) spawn(function() while player.Parent do task.wait(1) local isInGroup = false pcall(function() isInGroup = player:IsInGroup(GROUP_ID) end) local gain = isInGroup and INCREMENT_GROUP or INCREMENT_NON_GROUP if WalkSpeedValue.Value < MAX_SPEED then local adjustedGain = applyDiminishingReturn(WalkSpeedValue.Value, gain) WalkSpeedValue.Value += adjustedGain end end end)end)
rebirthEvent.OnServerEvent:Connect(function(player) local stats = player:FindFirstChild("leaderstats") if not stats then return end
local cash = stats:FindFirstChild("Cash") local rebirths = stats:FindFirstChild("Rebirths") if not cash or not rebirths then return end local nextCost = BASE_REBIRTH_COST * (rebirths.Value + 1) if cash.Value >= nextCost then cash.Value = 0 rebirths.Value += 1 local multiplier = rebirths.Value + 1 local existing = player:FindFirstChild("CashMultiplier") if not existing then local multi = Instance.new("IntValue") multi.Name = "CashMultiplier" multi.Value = multiplier multi.Parent = player else existing.Value = multiplier end rebirthEvent:FireClient(player, { rebirths = rebirths.Value, nextCost = BASE_REBIRTH_COST * (rebirths.Value + 1), multiplier = multiplier }) else rebirthEvent:FireClient(player, { error = "Not enough cash!" }) endend)
Players.PlayerRemoving:Connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then local WalkSpeedValue = leaderstats:FindFirstChild("WalkSpeed") local Cash = leaderstats:FindFirstChild("Cash") local Rebirths = leaderstats:FindFirstChild("Rebirths") if WalkSpeedValue then saveSpeed(player, WalkSpeedValue.Value) end if Cash then saveCash(player, Cash.Value) end if Rebirths then saveRebirths(player, Rebirths.Value) end end end)
game:BindToClose(function() for _, player in pairs(Players:GetPlayers()) do local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then local WalkSpeedValue = leaderstats:FindFirstChild("WalkSpeed") local Cash = leaderstats:FindFirstChild("Cash") local Rebirths = leaderstats:FindFirstChild("Rebirths") if WalkSpeedValue then saveSpeed(player, WalkSpeedValue.Value) end if Cash then saveCash(player, Cash.Value) end if Rebirths then saveRebirths(player, Rebirths.Value) end end end end) fix this or make it more stable at least
- Assistant
Here's an improved version of the script with enhanced stability and error handling:
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Wrap DataStore creation in pcall to handle potential service errors local function safeGetDataStore(name) local success, store = pcall(function() return DataStoreService:GetDataStore(name) end) if success then return store else warn("Failed to create DataStore: " .. name) return nil end end local WalkSpeedStore = safeGetDataStore("WalkSpeedDataStore") local CashStore = safeGetDataStore("CashDataStore") local RebirthStore = safeGetDataStore("RebirthDataStore") local MAX_SPEED = 9e99 local GROUP_ID = 36035362 local INCREMENT_NON_GROUP = 0.05 local INCREMENT_GROUP = 0.1 local OFFLINE_INCREMENT = 1 / 200 local BASE_REBIRTH_COST = 10000 local MAX_DATASTORE_RETRIES = 3 local DATASTORE_RETRY_DELAY = 1 -- Improved error handling for DataStore operations local function safeDataStoreGet(store, key) if not store then return nil end for attempt = 1, MAX_DATASTORE_RETRIES do local success, data = pcall(function() return store:GetAsync(key) end) if success then return data end warn("DataStore Get attempt " .. attempt .. " failed for key: " .. tostring(key)) task.wait(DATASTORE_RETRY_DELAY) end return nil end local function safeDataStoreSet(store, key, value) if not store then return false end for attempt = 1, MAX_DATASTORE_RETRIES do local success = pcall(function() store:SetAsync(key, value) end) if success then return true end warn("DataStore Set attempt " .. attempt .. " failed for key: " .. tostring(key)) task.wait(DATASTORE_RETRY_DELAY) end return false end -- Centralized function for creating ReplicatedStorage values local function ensureReplicatedStorageValue(name, valueType) local existingValue = ReplicatedStorage:FindFirstChild(name) if not existingValue then existingValue = Instance.new(valueType) existingValue.Name = name existingValue.Value = 0 existingValue.Parent = ReplicatedStorage end return existingValue end local offlineGainValue = ensureReplicatedStorageValue("OfflineGain", "NumberValue") local rebirthEvent = ensureReplicatedStorageValue("RebirthEvent", "RemoteEvent") -- Existing functions with minor improvements local function applyDiminishingReturn(current, gain) local distance = math.max(0, MAX_SPEED - current) return gain * (distance / MAX_SPEED) end local function loadSpeed(player) local data = safeDataStoreGet(WalkSpeedStore, player.UserId) return data and data.Speed or 0.00, data and data.LastLogout or os.time() end local function saveSpeed(player, speed) safeDataStoreSet(WalkSpeedStore, player.UserId, { Speed = speed, LastLogout = os.time() }) end local function loadCash(player) local cash = safeDataStoreGet(CashStore, player.UserId) return cash or 0 end local function saveCash(player, cash) safeDataStoreSet(CashStore, player.UserId, cash) end local function loadRebirths(player) local rebirths = safeDataStoreGet(RebirthStore, player.UserId) return rebirths or 0 end local function saveRebirths(player, rebirths) safeDataStoreSet(RebirthStore, player.UserId, rebirths) end -- Player Added Handler with improved error handling Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local WalkSpeedValue = Instance.new("NumberValue") WalkSpeedValue.Name = "WalkSpeed" WalkSpeedValue.Parent = leaderstats local Cash = Instance.new("NumberValue") Cash.Name = "Cash" Cash.Value = loadCash(player) Cash.Parent = leaderstats local Rebirths = Instance.new("IntValue") Rebirths.Name = "Rebirths" Rebirths.Value = loadRebirths(player) Rebirths.Parent = leaderstats local storedSpeed, lastLogout = loadSpeed(player) local now = os.time() local offlineTime = now - lastLogout local inGroup = pcall(function() return player:IsInGroup(GROUP_ID) end) and player:IsInGroup(GROUP_ID) local offlineGain = offlineTime * OFFLINE_INCREMENT * (inGroup and 2 or 1) local adjustedOfflineGain = applyDiminishingReturn(storedSpeed, offlineGain) storedSpeed = storedSpeed + adjustedOfflineGain WalkSpeedValue.Value = storedSpeed offlineGainValue.Value = math.max(0, adjustedOfflineGain) spawn(function() while player.Parent do task.wait(1) local isInGroup = pcall(function() return player:IsInGroup(GROUP_ID) end) and player:IsInGroup(GROUP_ID) local gain = isInGroup and INCREMENT_GROUP or INCREMENT_NON_GROUP if WalkSpeedValue.Value < MAX_SPEED then local adjustedGain = applyDiminishingReturn(WalkSpeedValue.Value, gain) WalkSpeedValue.Value += adjustedGain end end end) end) -- Rest of the script remains the same...Key improvements:
- Added robust error handling for DataStore operations
- Implemented retry mechanism for DataStore get and set
- Created a centralized function for ensuring ReplicatedStorage values
- Added more comprehensive error checking
- Improved group checking with pcall
- Added warning logs for potential issues
Recommendations:
- Implement proper logging (consider using a logging service)
- Add more comprehensive error handling
- Consider implementing a backup/fallback mechanism for data storage
- Monitor performance and adjust retry mechanisms as needed
Note: While this script improves stability, Roblox DataStores can still be unpredictable. Always have a backup plan and monitor your game's data integrity.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.