Returning booleans

Hey! I’m making a title system but can’t figure out how to fix this bug. Every time I try and return a Boolean like true or false it don’t update until I rejoin the game.

local function GetData(ItemName, TitlesData)
    for _, TitleName in pairs(TitlesData) do
		if tostring(ItemName) == tostring(TitleName) then
            return true -- It is true but still returns false **until** I rejoin the game.
        end
	end
    return false
end
local CheckData = GetData(ItemName, TitlesData)

if CheckData == true then
	print("Owns")
else
	print("Dont Own"
end

Is there a solution to fix this? Thanks! :grinning_face_with_smiling_eyes:

The print, you forgot to close the bracket. For the returns, I am not really sure. Is it the full code? If you stick with this issue, I would place the player to your game again so the data change with a prompt if we can’t solve this.

It seems to be an issue with either an outdated ItemName or outdated TitlesData that only update properly on a rejoin. The code works fine, but it’s probably something wrong with how you’re getting these 2 values to give to the function.

May we see the code you have that contains the call to GetData?

1 Like

I agree. And, can we also see your output to view any errors?

try printing different values to the console to see where your error is.

Yea, no problem

local function GetPlayerData()
    return EventModule.ClientCall("FetchClientData", "ScrollingFrame")
end
local function MakeButtons(i, v)

    local Data = GetPlayerData()
    
    local ItemName = v.Name
    local TitlesData = Data["Titles"]
    local CheckData = GetData(ItemName, TitlesData)

end
function TitleHandler:Int()

    for i,v in pairs(Titles) do -- Titles is a module where I add titles
        MakeButtons(i,v)
    end

end

Can you add somes print statements and play the game, from there show us the output and we will determine where the error start.

Could you print the contents of ItemName and TitlesData?

My only guess is that something is wrong when getting the TitlesData which is not updated till you rejoin. Maybe show what’s i nthe CLientCall?

Can’t be the name of the Item since you can’t really change a modulescript mid game

This is what the output says :grinning_face_with_smiling_eyes:

I think you need to refresh the data after the purchase.

it’s called “don’t own”, and that value is false. shouldn’t it be true that you don’t own?

That’s just the CheckData value, if I own it and rejoin it will print “Owns” but it will not update until I rejoin, and that’s what I’m trying to figure out :grinning_face_with_smiling_eyes:

oh i see now, sorry. :slight_smile:

There seems to be no errors. Maybe storing it using DataStores, so you store the rank immediatly once purchased, then you would change the title text to “RANK NAME HERE.” With example with DataStores when Immediatly purchased:

Expert
achdef

How does it save/update the data as of now when you buy a title? Could you show us the saving code?

Hey! Thanks for everyones help, just figured it out. The problem was that these 3 lines were in the wrong function

    local Data = GetPlayerData()
    
    local TitlesData = Data["Titles"]
    local CheckData = GetData(ItemName, TitlesData)
2 Likes