So, I'm having trouble getting a leaderstats string value to change automatically after an IntValue changes in correspondence to this. How would I go about doing this?
I have:
datastore = game:GetService("DataStoreService"):GetDataStore("rating") game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local rating = Instance.new("IntValue", leaderstats) rating.Name = "Rating" local ranking = Instance.new("StringValue", leaderstats) ranking.Name = "Rank" local key = "user_"..player.userId if (datastore:GetAsync(key) ~= 0) then rating.Value = datastore:GetAsync(key) else rating.Value = 1500 end rating.Changed:connect(function(val) datastore:SetAsync(key, val) end) if (rating.Value <= 1500) then ranking.Value = "Rust I" elseif (rating.Value > 1500 and rating.Value <= 2000) then ranking.Value = "Rust II" elseif (rating.Value > 2000 and rating.Value <= 2500) then ranking.Value = "Rust III" end end)
You aren't setting ranking.Value
inside of the Changed connection. You put that part after it, so it only gets set once. To solve that, put it inside the Changed event and set the initial value after the event is connected.
datastore = game:GetService("DataStoreService"):GetDataStore("rating") game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local rating = Instance.new("IntValue", leaderstats) rating.Name = "Rating" local ranking = Instance.new("StringValue", leaderstats) ranking.Name = "Rank" local key = "user_"..player.userId rating.Changed:connect(function(val) datastore:SetAsync(key, val) if (rating.Value <= 1500) then ranking.Value = "Rust I" elseif (rating.Value > 1500 and rating.Value <= 2000) then ranking.Value = "Rust II" elseif (rating.Value > 2000 and rating.Value <= 2500) then ranking.Value = "Rust III" end end) local init=datastore:GetAsync(key) if (init ~= 0) then rating.Value = init else rating.Value = 1500 end end)