I'm trying to make a saving database of someone's department in a group, I have a GUI which successfully changes the Department depending on the entry, but then here's my hard part, how to save it to a DataStore and retrieve it afterwards.
My attempt (Store)
local DataStore = game:GetService("DataStoreService"):GetDataStore("Departments")
local key = "user_" .. script.Parent.Parent.userId
script.Parent.Parent:WaitForChild("leaderstats").Department.Changed:connect(function()
DataStore:UpdateAsync(key,script.Parent.Parent:WaitForChild("leaderstats").Department.Value)
--This is where it stops working, "Unable to cast value to function"
end)
(Retrieve)
local group = 1234 --GroupID
local DataStore = game:GetService("DataStoreService"):GetDataStore("Departments")
game.Players.PlayerAdded:connect(function(player)
local leadrsts = Instance.new("IntValue",player)
leadrsts .Name = "leaderstats"
local rank = Instance.new("StringValue",leadrsts )
rank.Name = "Rank"
local department = Instance.new("StringValue",leadrsts )
department.Name = "Department"
local key = "user_" .. player.userId
department.Value = DataStore:GetAsync(key)
end)
Any help?
They're both server scripts

1 comment
Unless is a deeper reason for this happening + the reason I gave