#Problem with Datastore .State being false when trying to change values

1 messages · Page 1 of 1 (latest)

marble onyx
#
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local DataStoreModule = require(game.ServerStorage.DataStore)

local Local = {}
local Shared = {}

Local.Defaults = {
    Health = 100,
    Hunger = 100,
    Thirst = 100,
    Stamina = 100,
    PocketBalance = 0,
    BankBalance = 0,
    Honor = 0,
}

function Shared.OnStart()
    Players.PlayerAdded:Connect(function(player)
        local dataStore = DataStoreModule.new("Player", player.UserId)
        dataStore.StateChanged:Connect(Local.StateChanged)
        Local.StateChanged(dataStore.State, dataStore)
        print('player added data store created', dataStore.Value)
    end)
    
    Players.PlayerRemoving:Connect(function(player)
        local dataStore = DataStoreModule.find("Player", player.UserId)
        if dataStore ~= nil then dataStore:Destroy() end
        print('player removed data store destroyed')
    end)
end

function Local.StateChanged(state, dataStore)
    while dataStore.State == false do
        if dataStore:Open(Local.Defaults) ~= DataStoreModule.Response.Success then task.wait(6) end
        print('state changed')
    end
end

return Shared
marble onyx
#

I still can't figure out what the issue could be. dataStore.State seems to be false before updating datastore values. But I'm not sure why

toxic cloak
#

local.statechanged?

#

It should be throwing error right now

#

Local table has no state changed signal

marble onyx
# toxic cloak Local table has no state changed signal

Sorry, can you elaborate? I'm not able to understand what I would need to do differently. Right now, the code throws no errors.
This is all I see in my output right now: 19:47:03.102 player added wellness - Server - WellnessService:12 19:47:04.195 player added data store created ▶ {...} - Server - PlayerDataService:27

#

I'm trying to follow the modular framework outlined in this video: https://www.youtube.com/watch?v=13v62kybV7A
That's why there's Shared and Local tables

In this Roblox Scripting Tutorial, I'm going to teach you how to easily create your next Roblox game using the Module Framework. This framework provides us with an extremely intuitive and simple way of structuring and organizing our code and game.
Subscribe for more Roblox Scripting Tutorials!

Open-Source Roblox Game:
https://www.roblox.com/gam...

▶ Play video