Need help fixing a datastore update screen

Hello Former developers!
I am currently making an update screen for my game.

Here is the data store script:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("UpdateScreenSystem")

game.Players.PlayerAdded:connect(function(player)
 local updateFolder = Instance.new("Folder",player)
 updateFolder.Name = "UpdateValues"
 local Update = Instance.new("BoolValue",updateFolder)
 Update.Name = "UpdateTest2"
 Update.Value = ds:GetAsync(player.UserId) or true
 ds:SetAsync(player.UserId, Update.Value)
 Update.Changed:connect(function()
  ds:SetAsync(player.UserId, Update.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.UpdateValues.Update.Value)
end)

game.Players.PlayerAdded:Connect(function(player)
if update == true then
		game.ReplicatedStorage.ShowUpdateScreen:FireClient()
		wait(2)
		update = false
end

Here is the problem:
image
The folder UpdateValues is not registering as a real folder.
If you can help with this, please let me know. Thanks!
WE

2 Likes

First off.
You have 2 events for .PlayerAdded.
On the 2nd, ‘update’ is never defined tho.

2 Likes

Here is the new script:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("UpdateScreenSystem")

game.Players.PlayerAdded:connect(function(player)
 local updateFolder = Instance.new("Folder",player)
 updateFolder.Name = "UpdateValues"
 local Update = Instance.new("BoolValue",updateFolder)
 Update.Name = "UpdateTest2"
 Update.Value = ds:GetAsync(player.UserId) or true
 ds:SetAsync(player.UserId, Update.Value)
 Update.Changed:connect(function()
  ds:SetAsync(player.UserId, Update.Value)
 end)
end)

game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.UpdateValues.Update.Value)
end)

This one works fine. Do you know how I would be able to make it that the UpdateTest2 data will be able to fire a remote event if true then set it to false?

Yes.
Event.OnServerEvent:Connect(function(player goes here)
end)

Than, inside event, go in Player.UpdateValues.UpdateTest2

local updatedata = script.Parent.Parent.UpdateValues.UpdateTest2

if updatedata.Value == true then
	game.ReplicatedStorage.ShowUpdateScreen:FireClient()
end

image
I tried localscript and it doesn’t work.

If you want to fire a remote event when it’s changed to false, then simply do,

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("UpdateScreenSystem")

game.Players.PlayerAdded:connect(function(player)
	local updateFolder = Instance.new("Folder",player)
	updateFolder.Name = "UpdateValues"
	
	local Update = Instance.new("BoolValue",updateFolder)
	Update.Name = "UpdateTest2"
	Update.Value = ds:GetAsync(player.UserId) or true
	
	ds:SetAsync(player.UserId, Update.Value)
	Update:GetPropertyChangedSignal("Value"):Connect(function() -- If it doesn't work change it back to .Changed:Connect()

		MyRemoteName:FireClient(player, Update.Value) -- Fire RemoteEvent to Client

		ds:SetAsync(player.UserId, Update.Value)
	end)
	-- GetPropertyChangedSignal functions the same but checks when a specified property is changed.
end)

game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.UpdateValues.Update.Value)
end)

On the LocalScript do;

MyRemoteEvent.OnClientEvent:Connect(function(Update.Value)
	-- Whatever you want to happen when the value passes through.
end)

If you want to fire all the clients, use MyRemoteEvent:FireAllClients(Update.Value) instead of MyRemoteName:FireClient(player, Update.Value)

Only the localscripts that are waiting for the remote event will fire.

I also revised the code a bit, Using :GetPropertyChangedSignal is a better practice.

1 Like