DS = game:GetService("DataStoreService") MaxKi = DS:GetDataStore("kiMaxSave") game.Players.PlayerAdded:Connect(function(plr) print(plr.Name.."has joined the game") local stats = Instance.new("Folder", plr) stats.Name = "Stats" KiMax = Instance.new("NumberValue", stats) KiMax.Name = "KiMax" KiMax.Value = MaxKi:GetAsync(plr.UserId) or 0 KiValue = Instance.new("NumberValue", stats) KiValue.Name = "KiValue" KiValue.Value = KiMax.Value KiMax.Value.Changed:Connect(function() MaxKi:SetAsync(plr.UserId, KiMax) end) end)
I've made this and it says
18:14:38.674 - ServerScriptService.Script:13: attempt to index field 'Value' (a number value)
as an error.
.Changed
is an event of Instance, but you used it on the actual value of the instance, which is a number.
DS = game:GetService("DataStoreService") MaxKi = DS:GetDataStore("kiMaxSave") game.Players.PlayerAdded:Connect(function(plr) print(plr.Name.."has joined the game") local stats = Instance.new("Folder") --second argument of .new() deprecated stats.Name = "Stats" stats.Parent = plr KiMax = Instance.new("NumberValue", stats) KiMax.Name = "KiMax" KiMax.Value = MaxKi:GetAsync(plr.UserId) or 0 KiValue = Instance.new("NumberValue", stats) KiValue.Name = "KiValue" KiValue.Value = KiMax.Value KiMax.Changed:Connect(function() MaxKi:SetAsync(plr.UserId, KiMax) end) end)
Here's another example of using the event:
game:GetService("Players").PlayerAdded:Connect(function(plr) local IntValue = Instance.new("IntValue") IntValue.Parent = plr IntValue.Changed:Connect(function(property) print(property) end) wait(3) IntValue.Value = 5 --will print the name of the property changed - "Value" end)