I want to make so when a user clicks the submit buttons, I want the application answers to save onto a Datastore. This center is SCP genre so the apps will be sorted into different categories such as those for Level, and those for Department.
I’ve read the Datastore article on the Developer Hub and watched some videos, however I’m still confused on how to do this. Currently, all it does it fire all the answers to a script and then it does nothing.
Local Script:
mainApps.submit.TextButton.MouseButton1Click:Connect(function()
script.Parent.back.Visible = false
local answers = {
Question1 = {
Q1.TextLabel.Text,
Q1.TextBox.Text
},
Question2 = {
Q2.TextLabel.Text,
Q2.TextBox.Text
},
Question3 = {
Q3.TextLabel.Text,
Q3.TextBox.Text
},
Question4 = {
Q4.TextLabel.Text,
Q4.TextBox.Text
},
Question5 = {
Q5.TextLabel.Text,
Q5.TextBox.Text
},
}
local appType = script.AppType.Value
local AccountAge = game.Players.LocalPlayer.AccountAge
for i = 1, #"S E N D I N G . . ." do
mainApps.submit.TextButton.Text = string.sub("S E N D I N G . . .", 1, i)
wait(0.05)
end
game.ReplicatedStorage.RemoteEvent:FireServer(appType, AccountAge, answers)
end)
If anyone could show me the path that would be great. Thanks!
you would just save that answers table that you have there, datastores can also hold tables. What you can do is created a remote event in replicated storage and fire the event on the client and send the table over to the server to datastore
here is what you should have
--local script
game.ReplicatedStorage.RemoteEvent:FireServer(answers)
--ServerScript
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,applicationDataTbl)
--save data here
end)
In the ServerScript which will listen to FireServer you can setup function like this:
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = DataStoreService:GetDataStore("DataStoreName")
ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(funtion(Player, appType, AccountAge, answers)
-- I don't know maybe you want to check AccountAge and appType and save accordingly
local success, err = pcall(function()
DataStore:SetAsync(tostring(Player.Name), answers)
end)
end)
I would also suggest using DataStore2, since it makes it easy to read data anytime you want without getting dataStore single time