I got a big problem because my DataStore doesn't work and leaderstats doesn't work and I would like some help
Images for where is my stuff:
Biomes folder is in workspace: https://gyazo.com/4d4e99a072148068ef3eed78e09801f5 _ Other: https://gyazo.com/76fb3959c087032beafe3e78b8014a77
ServerScriptService Script:
local Players = game:GetService("Players") local RS = game:GetService("ReplicatedStorage") local SS = game:GetService("ServerStorage") local DSS = game:GetService("DataStoreService") local RunService = game:GetService("RunService") local ReplicatedModules = RS:WaitForChild("Modules") local InsCreator = require(ReplicatedModules.InstanceCreator) local DataStore = DSS:GetDataStore("Test") function GetRandomCFrame(Part,NewPart) local X, Z = Part.Size.X/2,Part.Size.Z/2 local RX,RZ = math.random(-X,X),math.random(-Z,Z) return Part.CFrame * CFrame.new(RX, {Part.Position.Y + NewPart.Size.Y + 0.3},RZ) end local function PlayerAdded(plr) local leaderstats = InsCreator.create("Folder", {Name = "leaderstats", Parent = plr}) local Tubes = InsCreator.create("IntValue", {Name = "Tubes", Value = 0}) local CURP = InsCreator.create("StringValue", {Name = "CURP", Value = 0}) local Rebirths = InsCreator.create("StringValue", {Name = "Rebirths", Value = 0}) local key = string.format("$s's data",plr.UserId) local success, err = pcall(function() local save = DataStore:GetAsync(key) if save then Tubes.Value = save[1] CURP.Value = save[2] Rebirths.Value = save[3] end end) if success then print(string.format("loaded $s's data",plr.Name)) elseif err then warn(err) end leaderstats.Parent = plr Tubes.Parent = leaderstats CURP.Parent = leaderstats Rebirths.Parent = leaderstats end local function PlayerRemoving(plr) local key = string.format("$s's data",plr.UserId) local ls = plr.leaderstats local success, err = pcall(function() DataStore:SetAsync(key,{ls.Tubes.Value, ls.CURP.Value, ls.Rebirths.Value}) end) if success then print(string.format("saved $s's data",plr.Name)) elseif err then warn(err) end end for a, biome in pairs(workspace:WaitForChild("Biomes"):GetChildren()) do spawn(function() RunService.Heartbeat:Connect(function() for i, tube in pairs(biome.Settings.Tubes:GetChildren()) do tube.CFrame = tube.CFrame * CFrame.fromEulerAnglesXYZ(0.02,0.02,0.02) end end) end) while true do if biome.Settings.MaxTubes.Value > #biome.Tubes:GetChildren() then local TubesToClone = biome.Settings.Tubes:Getchildren() local SelectedTubes = TubesToClone[math.random(1,#TubesToClone)] local NewTube = SS.Prefabs:FindFirstChild(SelectedTubes.Name):Clone() local Amount = math.random(math.floor(NewTube.Value.Value/1.25),math.floor(NewTube.Value.Value*1.25)) NewTube.CFrame = GetRandomCFrame(biome.Baseplate,NewTube) NewTube:WaitForChild("TubeValueGUI").Value.Text = Amount NewTube.Parent = biome.Tubes end end end Players.PlayerAdded:Connect(PlayerAdded) Players.PlayerRemoving:Connect(PlayerRemoving)
Module script in replicatedstorage:
local InstanceCreator = {} function InstanceCreator.create(class,properties) local newItem = {} newItem = Instance.new(class) for i, v in pairs(properties) do newItem[i] = v end return newItem end return InstanceCreator
Please help, thanks!
leaderstats don't work because you didn't put the parent of the values in the module script and also the string.format format is not
local key = string.format("$s's data",plr.UserId)
its actually this:
local key = string.format("%c's data",plr.UserId)