Hi! So I am making a system where you would buy a title in a shop (kind of like Epic Minigames) and when you leave it would save whether or not it has been bought. However, the brought Bool Value.Changed function does not work inside the onPlayerAdded function, however when I use the sae event outside the function, it activates. Please let me know why this is and how I should fix it please. Thank you.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("TitleSave1")
local brought = script.Parent -- Get Bool Value
local button = brought.Parent.BuyButton
local function onPlayerAdded(player)
brought.Value = ds:GetAsync(player.UserId) or false
if brought.Value == true then
button.Text = "Equip"
end
ds:SetAsync(player.UserId, brought.Value)
brought.Changed:Connect(function() -- This does not activate
print("Changed")
ds:SetAsync(player.UserId, brought.Value)
end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, brought.Value)
end)

4 comments
Also, PlayerRemoving also doesn't let me save the BoolValue, please can someone tell me why
You're adding .Changed after changing the value, it can never catch the change if its already happened.
So what should I do?
Move the .Changed above where the change happens.