Roblox Forum banner

How do I correctly save this?

229 Views 1 Reply 2 Participants Last post by  jumpcats1234
2
So, me and my friend are trying to make a rice farming simulator. He's the modeler and I'm the scripter. I've been able to use google for most of the problems I've had so far, besides this one. The problem is trying to save where people planted the rice. I have a little plot to plant rice, but it won't save correctly. Whenever I print, it shows that it's correct, but either it doesn't correctly save, or it doesn't load correctly, and I can't tell which one. (Sorry for the messy code)

Font Screenshot Technology Terrestrial plant Darkness

(this tells me that it saved)

Font Technology Screenshot Terrestrial plant Software

(this tells me that it didn't save, and this is part of the loading process)

Code:
local dataStoreService = game:GetService("DataStoreService")
local riceStore = dataStoreService:GetDataStore("RiceSpot1")

local function load(plr)
    local plrid = plr.UserId
    local GetSave = riceStore:GetAsync(plrid)
    
    if (GetSave) then
        for i, v in pairs(GetSave) do
            print(i, v)
            if (v == true) then
                local rice = game.ReplicatedStorage.RiceModels[plr.inventory['sR:1'].Value]:Clone()
                local spawner = script.Parent[i]
                local num = script.Parent.Name:split('_')
                print('e')
                
                rice.Name = "Rice_"..num[2]
                rice.Parent = script.Parent.Parent
                rice.Position = script.Parent["RiceSpawner_"..num[2]].Position
                rice.CanCollide = false
                rice.Size = Vector3.new(3.2, 6.2, 3.2)
                rice.Position = Vector3.new(spawner.Position.x, 3.005, spawner.Position.z)
            end
        end
    end
end

local function save(plr, ta)
    riceStore:SetAsync(plr.UserId, ta)
    print(ta)
end

game.Players.PlayerRemoving:Connect(function(plr)
    if (plr.Name == script.Parent.Parent.Parent.Parent.Owner.Value) then
        local spawners = script.Parent
        local dict = {
        }
        
        for _, spawner in ipairs(spawners:GetChildren()) do
            if not (spawner:IsA("Script")) then
                if (spawner:FindFirstChild("Planted")) then
                    dict[spawner.Name] = spawner.Planted.Value
                end
            end
        end

        save(plr, dict)
    end
end)

script.Parent.Parent.Parent.Parent.claimPart.ProximityPrompt.Triggered:Connect(function(plr)
    if (plr.Name == script.Parent.Parent.Parent.Parent.Owner.Value) then
        load(plr)
    end
end)
See less See more
1 - 2 of 2 Posts
I am not a scripter but maybe try to ask anyone of the Roblox Devforum for help
1 - 2 of 2 Posts
Top