Been making a game where players can modify weapons to use to fight one another, however I need to be able to save these guns as presets to individual players, and transfer the models themselves to another place within the game.
Here’s what modifying the weapons currently looks like.
Since players will be able to customize a number of different weapons with dozens of modifications (both of which I intend to add more of), It isn’t efficient or effective enough to make hundreds of separate tools saved to ReplicatedStorage for further use.
What I need is a way to…
- Assign saved models to a player’s account
- Transfer models between places
- Load saved models into ReplicatedStorage in the 2nd place
I’ve looked through a dozen topics that ask for similar systems, but most either come to the conclusion that it’s impossible, or that you can’t directly save the model, but only some of its values using a datastore (position, size, etc) (however, this system of saving & loading values wouldn’t work for me, as it involves making separate models for every variation of every weapon)
My current understanding of datastores is zero to none, but I believe that they are what I need to make this system work. But since datastores don’t allow instances to be saved, I need some kind of workaround to save these custom models to a player, and load them back into the game once the player rejoins.
local player = game.Players:FindFirstChildOfClass("Player")
local RS = game:GetService("ReplicatedStorage") -- gathers replicated storage for where the gun models will be stored
local datastore = game:GetService("DataStoreService"):GetDataStore("ModelData")
local modeldata = datastore:GetAsync(player.UserId)
local modstat = workspace["M4A1 MODDING STATION TM"]
local main = script.Parent
local SB1 = main.SaveButton1
local SB2 = main.SaveButton2
local SB3 = main.SaveButton3
SB1.MouseButton1Click:Connect(function()
local gun = modstat:FindFirstChild("M4A1") -- +
local gunclone = gun:Clone() -- +
gunclone.Parent = workspace -- +
local GM = gunclone:FindFirstChild("GunMain") -- +
local weldmaker = GM:FindFirstChildOfClass("Script") -- +
weldmaker.Enabled = true -- +
gunclone.Parent = RS -- this section of code (marked with a +) clones the gun the player has made and parents it to ReplicatedStorage
for _, stuff in ipairs(gunclone:GetChildren()) do
if stuff:IsA("Part") or stuff:IsA("UnionOperation") then
stuff.Anchored = false
elseif stuff:IsA("Model") then
for _, stuff2 in ipairs(stuff:GetChildren()) do
if stuff2:IsA("Part") or stuff2:IsA("UnionOperation") then
stuff2.Anchored = false -- this section of code (marked with a -) unanchors the gun so it can be used as a tool
end
end
end
end
end)
Here’s the code I currently have for saving the model.
This is the big thing I need help with
I’m unsure of how I can go about saving and loading models to a player, let alone how I can move the saved models between places.
Here’s what the current code looks like in action, with 3 separate guns being made, and equipped.
I’m hoping someone knows what a solution might be for me here, as I’m getting stumped looking through devforum posts and the official documentation. Help, suggestions, anything really, is greatly appreciated. Thanks!