So assuming you’re trying to load a users data and put it in to a screen gui?
Does the user have a datastore already made? If not have you created a default datastore for them?
You could do this multiple ways, such as creating one from scratch or replicating one. Very similar to how ScriptOn showed.
DefaultData = { -- Default data, only used if the user has never played before
['Name'] = nil,
["Symptoms"] = nil,
["Diagnosed"] = nil, -- Notice how this is NIL, you don't need to have this entire line due to it being nil. But it helps you read and understand where your datastore is.
["Supervisors"] = nil,
["Lead Doctor"] = nil, -- If you wanted the Lead Doctor to always be John Doe then you set it here, etc..
["Head Nurse"] = nil,
};
game:GetService("Players").PlayerAdded:connect(function(plr)
pcall(function() -- This will prevent any errors given (Like on the rare case that you are sending and recieving to much data)
local Data = DATASTORE:GetAsync(plr.UserId)
if Data == nil then
Data = DefaultData
end
DATASTORE:SetAsync(plr.UserId..DATAKEY,Data) -- We save the users data here (just incase it was the users first join)
end)
end)
As I said in the comment above… you don’t need to set the values to Nil (you could just remove them all together) but it helps organize and lets you read what your data is named, etc…
You can then assign a user data by simply changing the value’s we set to nil. So if you wanted a user to need to check in at the desk you would make a script to change the users table.
local Data = DATASTORE:GetAsync(plr.UserId) -- If you don't want to always load the users data in then you can make globals.
Data.Name = tostring(plr.Name)
Data.Symptons = sympton1,sympton2 -- Sympton1 would be whatever the user said or whatever your randomizer etc.. is
Although if you are using multiple scripts then you may want to use a global to add data from one script to another. I would recommend sending the data with it (that way you don’t need to load in the data over and over! this will also prevent users from spamming it.
_G.updateValue = function(plr,updating,newvalue)
pcall(function()
local Data = DATASTORE:GetAsync(plr.UserId)
Data[updating] = newvalue
end)
end
Earlier you were asking about if you can have a table inside of a table! This is completely fine. You can set your defaultdata or the users data to whatever you want.
DefaultData = { -- Default data, only used if the user has never played before
['Name'] = nil,
["Symptoms"] = {
Symptom1 = "Bleeding in the far left toe";
Symptom2 = "Massive ear ache";
};
["Diagnosed"] = {
BrokenLeftArm = false;
BrokenRightArm = false;
NailInToe = false;
};
["Supervisors"] = {
Supervisor1 = nil;
Supervisor2 = nil;
};
["Lead Doctor"] = nil, -- If you wanted the Lead Doctor to always be John Doe then you set it here, etc..
["Head Nurse"] = nil,
};
Becuase of the bleeding toe, you know that its most likely a nail in the toe! You can set this to true very simply.
Data.Diagnosed.NailInToe = true
Now if you wanted to make Supervisor1 John Doe then you can simply change that value like we did before!
Data.Supervisors.Supervisor1 = "John Doe"
But lets say you wanted to add Supervisors and didn’t just want two! Then you can simply make a new value and set it to nil via scripts.
if Data.Supervisors["Supervisor3"] = nil then
Data.Supervisors["Supervisor3"] = Jane Doe
end
But what if we wanted to make this more advanced? What if we wanted to check the Diagnostics and then give the user a sympton based on it? That is also very plausible.
if Data.Symptoms.Symptom1 == "Bleeding in Toe" then
if Data.Symptoms.Symptom2 == "Headache" then
Data.Diagnosed = "Nail in Toe" -- Or Data.Diagnosed.NailInToe = tru3
end
if Data.Symptons.Sympton2 == "Pain in Toe" then
Data.Diagnosed = "Cut on Toe" -- Or Data.Diagnosed.CutOnToe = tru3
end
end
Now lets put everything together to make a working script!
(I have not testing this script, if it doesn’t work then I apologize ahead of time)
DefaultData = { -- Default data, only used if the user has never played before
['Name'] = nil,
["Symptoms"] = {
Symptom1 = nil;
Symptom2 = nil;
};
["Diagnosed"] = {
BrokenLeftArm = false;
BrokenRightArm = false;
NailInToe = false;
CutInToe = false;
};
["Supervisors"] = {
Supervisor1 = nil;
Supervisor2 = nil;
};
["Lead Doctor"] = nil, -- If you wanted the Lead Doctor to always be John Doe then you set it here, etc..
["Head Nurse"] = nil,
};
local DataStoreService = game:GetService("DataStoreService")
local DATASTORE = DataStoreService:GetDataStore("UserData")
function checkSymptoms(plr)
local Data = DATASTORE:GetAsync(plr.UserId)
if Data.Symptoms.Symptom1 == "Bleeding in Toe" then
if Data.Symptoms.Symptom2 == "Headache" then
Data.Diagnosed.NailInToe = true;
end
if Data.Symptons.Sympton2 == "Pain in Toe" then
Data.Diagnosed.CutInToe = true;
end
end
end
_G.updateValue = function(plr,updating,newvalue) -- The player, the value to change, the new value
pcall(function()
local Data = DATASTORE:GetAsync(plr.UserId)
updating = newvalue
end)
end
game:GetService("Players").PlayerAdded:connect(function(plr)
local Data = DATASTORE:GetAsync(plr.UserId)
pcall(function() -- This will prevent any errors given (Like on the rare case that you are sending and recieving to much data)
if Data == nil then
Data = DefaultData
end
DATASTORE:SetAsync(plr.UserId,Data) -- We save the users data here (just incase it was the users first join)
end)
wait(6) -- Wait 10 seconds then update the symptoms
_G.updateValue(plr,Data["Symptoms"]["Symptom1"],"Headache")
checkSymptoms(plr)
end)
I hope this helped! If you need more help feel free to respond or send me a direct message!