Hello, i am trying to make an OC saving/loading system, so far im pretty okayish on the saving portion, but for the life of me i cannot figure out the loading part.
so im using a table to list out features that are important, the script im going to show is a test to just detect the character model type and then when you load it to morph you into the model you saved.
here is the saving portion of the script, this part is on a Server script, after firing the function from the client with a GUI button
save.OnServerEvent:Connect(function(player, Slot, model)
local uniqueID = HttpService:GenerateGUID(false)
playerSlots[uniqueID] = {
Save = Slot, -- this is to check which slot they are saving in (I.E: save 1 or save 2 etc)
Model = model, -- this is to check the model they are, im using the numbers, 1 or 2, this is 1
unique = uniqueID -- i dont think i need to save this but i just kept it here from previous attempts
}
print(playerSlots[uniqueID].Model, playerSlots[uniqueID].Save) -- to make sure it worked
if playerSlots[uniqueID].Save == 1 then -- Checking which save it is
save1:SetAsync(playerSlots[uniqueID], player.UserId) -- saving the playerslots to the respective save datastore
print("saved")
end
end)
and then this is the loading portion, thats giving me the MOST trouble.
load.OnServerEvent:Connect(function(player, Slot)
local save = Slot
if save == 1 then -- checking the save
save1:GetAsync(player.UserId) -- grabbing the save
print(playerSlots.Model) -- <- prints "nil"
if playerSlots.Model == 1 then --- this is the morphing script VVV and it doesnt work
print("model is a worker drone")
local morph = game.ReplicatedStorage.Morphs.Live
local char = morph:Clone()
char.Name = player.Name
player.Character = char
char.Parent = workspace
end
end
end)
if i try to say
print(playerSlots[uniqueID].Model)
it says that it tried to index nil with model, i tried to save the uniqueID itself into the datastore but it says its “unable to cast array”.
there are a few other things i’ve tried that i dont remember but this whole thing has been pretty angering for me.
heres the full entire script if it helps, plus the client one.
--- server script
local save = game.ReplicatedStorage.saving.Save
local load = game.ReplicatedStorage.saving.Load
local players = game:GetService("Players")
local playerSlots = {}
local HttpService = game:GetService("HttpService")
local Data = game:GetService("DataStoreService")
local save1 = Data:GetDataStore("Save1")
local save2 = Data:GetDataStore("Save2")
save.OnServerEvent:Connect(function(player, Slot, model)
local uniqueID = HttpService:GenerateGUID(false) -- creating a unique id
playerSlots[uniqueID] = {
Save = Slot, -- checking which slot they're saving
Model = model,
unique = uniqueID
}
print(playerSlots[uniqueID].Model, playerSlots[uniqueID].Save)
if playerSlots[uniqueID].Save == 1 then -- Checking which save it is
save1:SetAsync(playerSlots[uniqueID], player.UserId) -- saving the playerslots to the respective save datastore
print("saved")
end
end)
---
load.OnServerEvent:Connect(function(player, Slot)
local save = Slot
if save == 1 then
save1:GetAsync(player.UserId)
print(playerSlots.Model)
if playerSlots.Model == 1 then
print("model is a worker drone")
local morph = game.ReplicatedStorage.Morphs.Live
local char = morph:Clone()
char.Name = player.Name
player.Character = char
char.Parent = workspace
end
end
end)
--- local script, attached to GUI buttons
local save = script.Parent.SAVE
local load = script.Parent.LOAD
local player = game.Players.LocalPlayer
local playerSlots = {}
local model
save.MouseButton1Click:Connect(function()
local Slot = 1
if player.Character.ID.Value == 1 then
model = 1
else
model = 2
end
game.ReplicatedStorage.saving.Save:FireServer(Slot, model)
end)
load.MouseButton1Click:Connect(function()
local Slot = 1
game.ReplicatedStorage.saving.Load:FireServer(Slot)
end)
Note: im not sure how important it is, but i am not using a roblox model, im using a blender created model.
let me know if there’s anything i forgot to add or if you need to know