Hi everyone, I'm really really confused.
For context, I have a gui in starterGui that has a local script that makes it so when a remote (from my datastore script, ill show it later it's huge lmao) is called to the player, a gui comes up for them to choose 1 of 6 colors. When they choose a color, the color button does invokeserver() to the datastore script, the color is sent from the function on the local script to the receiver on the datastore script so thats how it's obtained.
Then the remote function on the datastore sets a saved bool and string values, with the bool being: "HasChosenColor" and the string just being a tostring() color sent from the local script.
I'm probably not explaining this well, english isn't my first language. I think it'd be better if I showed ya the scripts and did a light explanation on each.
Here's the LocalScript which is a child of the Color Choosing ScreenGui:
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character |
03 | script.Parent.Frame.Visible = false |
04 | script.Parent.Frame.Position = UDim 2. new( 0.31 , 0 , 1.067 , 0 ) |
06 | game.ReplicatedStorage.Remotes.ColorSelectPrompt.OnClientEvent:connect( function (player) |
08 | char.Humanoid.WalkSpeed = 0 |
09 | local fgui 1 = script.Parent.Frame |
10 | local fgui 1 p = script.Parent |
13 | fgui 1 :TweenPosition(UDim 2. new( 0.31 , 0 , 0.707 , 0 )) |
This script just shows the gui when a remote is fired on the DataStore script. The remote is fired when "HasChosenColor" value inside the player is false.
Before I show the DataStore script here's the LocalScript that's a child of every TextButton.
(This local script is the exact same for every button but the Color at the top matches the button.)
01 | local result = tostring ( "Black" ) |
02 | local plr = game.Players.LocalPlayer |
03 | local pchar = plr.Character |
04 | script.Parent.Size = UDim 2. new( 0 , 76 , 0 , 74 ) |
05 | script.Parent.MouseButton 1 Down:connect( function () |
06 | pchar.Humanoid.WalkSpeed = 16 |
07 | script.Parent:TweenSize(UDim 2. new( 0 , 90 , 0 , 88 )) |
08 | script.Parent.Parent.ColorDeepOrange.Active = false |
09 | script.Parent.Parent.ColorPersimmons.Active = false |
10 | script.Parent.Parent.ColorInstituionalWhite.Active = false |
11 | script.Parent.Parent.ColorReallyRed.Active = false |
12 | script.Parent.Parent.ColorElectricBlue.Active = false |
13 | game.ReplicatedStorage.Remotes.ColorSelectResult 1 :InvokeServer(result) |
14 | script.Parent.Parent.Parent.Frame:TweenPosition(UDim 2. new( 0.31 , 0 , 1.067 , 0 )) |
15 | script.Parent.Parent.Parent.Frame.Visible = false |
16 | script.Parent.Parent.Parent.Frame.Active = false |
That local script just tells the DataStore script that a color was chosen through a remote function.
Here's the biggy, and if you were confused til now you'll probably understand it. There are a lot of things in this script that don't relate to the problem but I thought I should include the full thing because it contains the error. (Warning, huge script)
001 | local maxcount = 500000000000 |
003 | local dss = game:GetService( "DataStoreService" ):GetDataStore(REDACTED) |
004 | local di = game:GetService( "ServerStorage" ):WaitForChild( "DataIndex" ) |
005 | local AutosaveInterval = 60 |
006 | game.Players.PlayerAdded:connect( function (player) |
007 | local playerdata = Instance.new( "Folder" , di) |
008 | playerdata.Name = player.Name |
010 | local din = player.Name |
012 | local stats = Instance.new( "Folder" , playerdata) |
013 | stats.Name = "Stats1" |
015 | local ArcaneCount = Instance.new( "IntValue" , stats) |
016 | ArcaneCount.Name = "Arcane" |
018 | local leaderstatfolder = Instance.new( "Folder" , player) |
019 | leaderstatfolder.Name = "leaderstats" |
021 | local WillpowerCount = Instance.new( "IntValue" , stats) |
022 | WillpowerCount.Name = "Willpower" |
024 | local HasChosenColor = Instance.new( "BoolValue" , stats) |
025 | HasChosenColor.Name = "HasChosenColor" |
027 | local Arcin = Instance.new( "IntValue" , leaderstatfolder) |
028 | Arcin.Name = "Arcine" |
030 | local lac 3 = Instance.new( "IntValue" , leaderstatfolder) |
033 | local lac 2 = Instance.new( "IntValue" , leaderstatfolder) |
034 | lac 2. Name = "Willpower" |
037 | local CoinsCount = Instance.new( "IntValue" , stats) |
038 | CoinsCount.Name = "Coins" |
040 | local ChosenColorB = Instance.new( "StringValue" , leaderstatfolder) |
041 | ChosenColorB.Name = "ChosenColorB" |
043 | local OtherData = Instance.new( "Folder" , playerdata) |
044 | OtherData.Name = "Other" |
047 | local SavedData = dss:GetAsync(player.userId) |
050 | local BrickCooler = Instance.new( "BrickColorValue" , OtherData) |
051 | BrickCooler.Name = "BrickCooler" |
053 | if HasChosenColor.Value = = false then |
054 | game.ReplicatedStorage.Remotes.ColorSelectPrompt:FireClient(player) |
057 | BrickCooler.Value = BrickColor.new(ChosenColorB.Value) |
067 | game.ReplicatedStorage.Remotes.MaxArcane 1. OnServerInvoke = function (player, pname) |
068 | di [ pname ] .Stats 1. Arcane.Value = game.ServerStorage.DataIndex [ pname ] .Stats 1. Arcane.Value + maxcount |
069 | game.Players [ pname ] .leaderstats.Arcine.Value = game.Players [ pname ] .leaderstats.Arcine.Value + maxcount |
074 | game.ReplicatedStorage.Remotes.MaxWillpower 1. OnServerInvoke = function (player, pname) |
075 | di [ pname ] .Stats 1. Willpower.Value = game.ServerStorage.DataIndex [ pname ] .Stats 1. Willpower.Value + maxcount |
076 | game.Players [ pname ] .leaderstats.Willpower.Value = game.Players [ pname ] .leaderstats.Willpower.Value + maxcount |
079 | game.ReplicatedStorage.Remotes.GlobalResetStats.OnServerEvent:connect( function () |
080 | ArcaneCount.Value = 0 |
081 | WillpowerCount.Value = 0 |
088 | game.ReplicatedStorage.Remotes.ResetStats.OnServerInvoke = function (player, pname) |
089 | di [ pname ] .Stats 1. Willpower.Value = 0 |
090 | game.Players [ pname ] .leaderstats.Willpower.Value = 0 |
091 | di [ pname ] .Stats 1. Coins.Value = 0 |
092 | game.Players [ pname ] .leaderstats.Coins.Value = 0 |
093 | di [ pname ] .Stats 1. Arcane.Value = 0 |
094 | game.Players [ pname ] .leaderstats.Arcine.Value = 0 |
096 | game.ReplicatedStorage.Remotes.IncreaseArcane 1. OnServerInvoke = function (player, pname) |
097 | di [ pname ] .Stats 1. Arcane.Value = di [ pname ] .Stats 1. Arcane.Value + 1 |
098 | game.Players [ pname ] .leaderstats.Arcine.Value = player.leaderstats.Arcine.Value + 1 |
101 | game.ReplicatedStorage.Remotes.IncreaseWillpower 1. OnServerInvoke = function (player, pname) |
102 | di [ pname ] .Stats 1. Willpower.Value = di [ pname ] .Stats 1. Willpower.Value + 5 |
103 | game.Players [ pname ] .leaderstats.Willpower.Value = player.leaderstats.Willpower.Value + 5 |
108 | print ( 'Data currently used:' ..game:GetService( "HttpService" ):JSONEncode(SavedData):len().. '/260000 bytes' ) |
109 | for i,v in pairs (SavedData) do |
112 | di [ player.Name ] .Stats 1 :FindFirstChild(SavedData [ i - 1 ] ).Value = v |
115 | Arcin.Value = ArcaneCount.Value |
116 | lac 2. Value = WillpowerCount.Value |
117 | lac 3. Value = CoinsCount.Value |
123 | local function SaveStats(player) |
124 | local DataCollective = { } |
125 | for i,v in pairs (di [ player.Name ] .Stats 1 :GetChildren()) do |
126 | DataCollective [ #DataCollective + 1 ] = v.Name |
127 | DataCollective [ #DataCollective + 1 ] = v.Value |
130 | local pnameout = player.Name |
131 | print (pnameout.. "'s Data was saved." ) |
132 | dss:SetAsync(player.userId, DataCollective) |
135 | game.ReplicatedStorage.Remotes.ColorSelectResult 1. OnServerInvoke = function (player, result) |
137 | local din = player.Name |
138 | di [ din ] .Stats 1. HasChosenColor.Value = true |
139 | game.Players [ din ] .leaderstats.ChosenColorB.Value = result |
140 | di [ din ] .Other.BrickCooler.Value = BrickColor.new(result) |
150 | game:BindToClose( function () |
151 | for i, player in pairs (game.Players:GetPlayers()) do |
155 | game.Players.PlayerRemoving:connect( function (player) |
159 | while wait(AutosaveInterval) do |
160 | for i, player in pairs (game.Players:GetPlayers()) do |
Welp, that was big. Anyway, things important to note is a value ChosenColorB is created which acts as the color that is sent from the local script.
First thing you'll notice is that BrickCooler (the brickcolor value) isnt saved with the rest. That's intentional because i can't save BrickColor values. So when the remote function from the local script is invoked the brickcolor value is set to the ChosenColorB value, and here's the main problem. "HasChosenColor" is set to true when that remote is invoked.
And I have an if statement higher up in the script at around Line 53. When the game is done doing all the loading the if statement checks if HasChosenColor is false. Naturally it shouldn't be, everytime I choose a color, save, then exit and reload the game the output reads:
Data currently used:58/260000 bytes
1 Arcane
2 0
3 Willpower
4 0
5 HasChosenColor
6 true
7 Coins
8 0
And that's where the madness begins, if it's true and the game knows it, why is the If statement not recognizing that? It's breaking everything and it's so annoying ;-; pls help