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

If statement trouble, what the heck am I doing wrong??

Asked by
Gojinhan 353 Moderation Voter
5 years ago

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:

01local player = game.Players.LocalPlayer
02local char = player.Character
03script.Parent.Frame.Visible = false
04script.Parent.Frame.Position = UDim2.new(0.31, 0,1.067, 0)
05 
06game.ReplicatedStorage.Remotes.ColorSelectPrompt.OnClientEvent:connect(function(player)
07    wait(3)
08    char.Humanoid.WalkSpeed = 0
09    local fgui1 = script.Parent.Frame
10    local fgui1p = script.Parent
11 
12    fgui1.Visible = true
13    fgui1:TweenPosition(UDim2.new(0.31, 0,0.707, 0))
14end)

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.)

01local result = tostring("Black")
02local plr = game.Players.LocalPlayer
03local pchar = plr.Character
04script.Parent.Size = UDim2.new(0, 76,0, 74)
05script.Parent.MouseButton1Down:connect(function()
06    pchar.Humanoid.WalkSpeed = 16
07    script.Parent:TweenSize(UDim2.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.ColorSelectResult1:InvokeServer(result)
14    script.Parent.Parent.Parent.Frame:TweenPosition(UDim2.new(0.31, 0,1.067, 0))
15    script.Parent.Parent.Parent.Frame.Visible = false
16    script.Parent.Parent.Parent.Frame.Active = false
17end)

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)

001local maxcount = 500000000000
002 
003local dss = game:GetService("DataStoreService"):GetDataStore(REDACTED)
004local di = game:GetService("ServerStorage"):WaitForChild("DataIndex")
005local AutosaveInterval = 60
006game.Players.PlayerAdded:connect(function(player)
007    local playerdata = Instance.new("Folder", di)
008    playerdata.Name = player.Name
009 
010    local din = player.Name
011 
012    local stats = Instance.new("Folder", playerdata)
013    stats.Name = "Stats1"
014 
015    local ArcaneCount = Instance.new("IntValue", stats)
View all 163 lines...

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

2 answers

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

We talked it over on discord for anyone wondering. The issue was that we weren't loading the data from the datastore

we saved the data in a table like this:

1DataCollective = {
2    ["Arcane"] = 10,
3    ["ChosenColorA"] = 10,
4    ["Coins"] = 10,
5    ["HasChosenColor"] = 10,
6    ["Willpower"] = 10       
7}

and after we got the data with getasync() we assigned the data in the datastore to the object values in the game using this function:

1function assignDataToFolder(player, data)
2    for _, variable in pairs(di[player.Name].Stats1:GetChildren())do
3        variable.Value = data[variable.Name]
4    end
5end

if anyone else reading this post has a similar issue, let me know on discord, Lucy# 4 8 5 4

Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago

The problem is that you are reading the HasChosenColor value, BEFORE it is read from your saving storage. To make it work, you will need to move whole statement:

1if HasChosenColor.Value == false then
2    game.ReplicatedStorage.Remotes.ColorSelectPrompt:FireClient(player)
3else
4    print("cmon put it")
5    BrickCooler.Value = BrickColor.new(ChosenColorB.Value)
6end

AFTER the read data segment (below line 118).

Answer this question