I recently did a with LocalScript key changing system (If you want to change a key, press the textbox and change it) change key to crouch, KeyboardKeyCode, Open GUI, Etc. But I don’t know how to make a dataStore with that
This is an example of a DataStore that saves a StringValue I made, you can change some parts of this script to save what you need.
In other DataStore it gives me the same error, and I don’t know how to solve it
local ds = game:GetService("DataStoreService")
local valueDs = ds:GetDataStore("valueDs")
game.Players.PlayerAdded:Connect(function(player)
local Keys = Instance.new("Folder")
Keys.Name = "Keys"
Keys.Parent = player
local MenuKey = Instance.new("StringValue")
MenuKey.Name = "MenuKey"
MenuKey.Parent = Keys
MenuKey.Value = "M"
local InteractiveKey = Instance.new("StringValue")
InteractiveKey.Name = "InteractiveKey"
InteractiveKey.Parent = Keys
InteractiveKey.Value = "F"
local AgacharseKey = Instance.new("StringValue")
AgacharseKey.Name = "AgacharseKey"
AgacharseKey.Parent = Keys
AgacharseKey.Value = "C"
local EmotesKey = Instance.new("StringValue")
EmotesKey.Name = "EmotesKey"
EmotesKey.Parent = Keys
EmotesKey.Value = "B"
local data
local success, errormessage = pcall(function()
data = valueDs:GetAsync(player.UserId.."-stringValue")
end)
if success then
MenuKey.Value = data
InteractiveKey.Value = data
AgacharseKey.Value = data
EmotesKey.Value = data
else
print("No se pudieron guardar los datos")
wait(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
valueDs:SetAsync(player.UserId.."-stringValue", player.Keys.MenuKey.Value)
valueDs:SetAsync(player.UserId.."-stringValue", player.Keys.InteractiveKey.Value)
valueDs:SetAsync(player.UserId.."-stringValue", player.Keys.AgacharseKey.Value)
valueDs:SetAsync(player.UserId.."-stringValue", player.Keys.EmotesKey.Value)
end)
if success then
print("Guardado exitosamente")
else
print("Error al guardar datos")
warn(errormessage)
end
end)
“-stringValue” must be changed with the name of your StringValue
It no longer gives me any error, but it does not save
This?
local success, errormessage = pcall(function()
valueDs:SetAsync(player.UserId.."-MenuKey", player.Keys.MenuKey.Value)
valueDs:SetAsync(player.UserId.."-InteractiveKey", player.Keys.InteractiveKey.Value)
valueDs:SetAsync(player.UserId.."-AgacharseKey", player.Keys.AgacharseKey.Value)
valueDs:SetAsync(player.UserId.."-EmotesKey", player.Keys.EmotesKey.Value)
Yes you must insert the name of the stringValues you’ve created.
Insead of writing Multiple SetAsync requests, Just use a dictionary:
local Data = {
["MenuKey"] = Player.Keys.MenuKey.Value -- Repeat for all of them
}
local Success,Err = pcall(function()
ValueDs:SetAsync(Player.UserId, Data)
end)
Now it gives me an error of …
local ds = game:GetService("DataStoreService")
local valueDs = ds:GetDataStore("valueDs")
game.Players.PlayerAdded:Connect(function(player)
local Keys = Instance.new("Folder")
Keys.Name = "Keys"
Keys.Parent = player
local MenuKey = Instance.new("StringValue")
MenuKey.Name = "MenuKey"
MenuKey.Parent = Keys
MenuKey.Value = "M"
local InteractiveKey = Instance.new("StringValue")
InteractiveKey.Name = "InteractiveKey"
InteractiveKey.Parent = Keys
InteractiveKey.Value = "F"
local AgacharseKey = Instance.new("StringValue")
AgacharseKey.Name = "AgacharseKey"
AgacharseKey.Parent = Keys
AgacharseKey.Value = "C"
local EmotesKey = Instance.new("StringValue")
EmotesKey.Name = "EmotesKey"
EmotesKey.Parent = Keys
EmotesKey.Value = "B"
local data = {
["MenuKey"] = player.Keys.MenuKey.Value,
["InteractiveKey"] = player.Keys.InteractiveKey.Value,
["AgacharseKey"] = player.Keys.AgacharseKey.Value,
["EmotesKey"] = player.Keys.EmotesKey.Value,-- Repeat for all of them
}
local success,Err = pcall(function()
valueDs:SetAsync(player.UserId, data)
end)
if success then
MenuKey.Value = data
InteractiveKey.Value = data
AgacharseKey.Value = data
EmotesKey.Value = data
else
print("No se pudieron guardar los datos")
wait(Err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, Err = pcall(function()
valueDs:SetAsync(player.UserId.."-MenuKey", player.Keys.MenuKey.Value)
valueDs:SetAsync(player.UserId.."-InteractiveKey", player.Keys.InteractiveKey.Value)
valueDs:SetAsync(player.UserId.."-AgacharseKey", player.Keys.AgacharseKey.Value)
valueDs:SetAsync(player.UserId.."-EmotesKey", player.Keys.EmotesKey.Value)
end)
if success then
print("Guardado exitosamente")
else
print("Error al guardar datos")
warn(Err)
end
end)
Put it in the PlayerRemoving event…
By the way, In the first Success/Err statment use GetAsync not SetAsync
Well now it is “saved” correctly, it does not give any error but it does not save, is it because the value that a LocalScript changes?
local ds = game:GetService("DataStoreService")
local valueDs = ds:GetDataStore("valueDs")
game.Players.PlayerAdded:Connect(function(player)
local Keys = Instance.new("Folder")
Keys.Name = "Keys"
Keys.Parent = player
local MenuKey = Instance.new("StringValue")
MenuKey.Name = "MenuKey"
MenuKey.Parent = Keys
MenuKey.Value = "M"
local InteractiveKey = Instance.new("StringValue")
InteractiveKey.Name = "InteractiveKey"
InteractiveKey.Parent = Keys
InteractiveKey.Value = "F"
local AgacharseKey = Instance.new("StringValue")
AgacharseKey.Name = "AgacharseKey"
AgacharseKey.Parent = Keys
AgacharseKey.Value = "C"
local EmotesKey = Instance.new("StringValue")
EmotesKey.Name = "EmotesKey"
EmotesKey.Parent = Keys
EmotesKey.Value = "B"
local data
local success, Err = pcall(function()
data = valueDs:GetAsync(player.UserId.."-MenuKey")
data = valueDs:GetAsync(player.UserId.."-InteractiveKey")
data = valueDs:GetAsync(player.UserId.."-AgacharseKey")
data = valueDs:GetAsync(player.UserId.."-EmotesKey")
end)
if success then
MenuKey.Value = data
InteractiveKey.Value = data
AgacharseKey.Value = data
EmotesKey.Value = data
else
print("No se pudieron guardar los datos")
wait(Err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {
["MenuKey"] = player.Keys.MenuKey.Value,-- Repeat for all of them
["InteractiveKey"] = player.Keys.MenuKey.Value, -- Repeat for all of them
["AgacharseKey"] = player.Keys.MenuKey.Value, -- Repeat for all of them
["EmotesKey"] = player.Keys.MenuKey.Value -- Repeat for all of them
}
local success,Err = pcall(function()
valueDs:SetAsync(player.UserId, data)
end)
if success then
print("Guardado exitosamente")
else
print("Error al guardar datos")
warn(Err)
end
end)
You’re keys are messed up, you’re saving with a different key and getting with a different key
Instead of setting all of them to data, do this:
MenuKey.Value = data[1]
InteractiveKey.Value = data[2]
AgacharseKey.Value = data[3]
EmotesKey.Value = data[4]