Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

? I want to save the models - that the player placed - when they leave. I'm a bit confused how

Asked by 6 years ago
Edited 6 years ago

Here is my script:



Data = game:GetService("DataStoreService"):GetDataStore("BlastOffMoonData") JSON = game:GetService("HttpService") local base local corner game.Players.PlayerAdded:connect(function(Player) repeat wait() until Player.Character repeat wait() until workspace.TestTycoon.Owner.Value ~= '' if workspace.TestTycoon.Owner.Value == Player.Name then Tycoon = workspace.TestTycoon base = Tycoon.Base corner = Tycoon.Base.Position - (Tycoon.Base.Size/3) end local plrData = Data:GetAsync(Player.UserId) if plrData then print(JSON:JSONEncode(plrData)) Player.Money.Value = tonumber(plrData.Money) for i, Object in pairs(game:GetService("ReplicatedStorage").GameItems:GetChildren()) do for e, Data in pairs(plrData) do if Object.Name == Data[1] then local newObject = Object:Clone() newObject.Parent = Tycoon.TestItems local location =tonumber(Data[2],Data[3],Data[4]) newObject:SetPrimaryPartCFrame(CFrame.new(Data[2], Data[3], Data[4])) end end end end end)

The player removing save part:


game.Players.PlayerRemoving:connect(function(plr) local playerData = { Money = plr.Money.Value, Placed = {["itemPositions"] = {} } } if plr.leaderstats.SandboxSlot.Value == 'Sandbox1' then Tycoon = workspace.TestTycoon end for i, v in pairs(Tycoon.TestItems:GetChildren()) do if v:IsA('Model') then table.insert(playerData, {v.Name, v.PrimaryPart.Position.x,v.PrimaryPart.Position.y, v.PrimaryPart.Position.z}) end end print( JSON:JSONEncode( playerData ) ) Data:SetAsync(plr.UserId, playerData) end)
0
You should fix your code's indentation BlueTaslem 18071 — 6y
0
is that the problem? therealae 7 — 6y
0
No, nobody is going to read code thats not formatted. H4X0MSYT 536 — 6y

Answer this question