I’m not the best coder, but I know a bit. I was wondering if there was a way where I can make it so a model that a player purchased is saved in workspace so that when they rejoin it will still be there, and for the player only. If anyone knows how to do it or if there is a post for this already or a tutorial online, I appreciate all the help I can get! Thanks!
Are you trying to make it save in 1 server or save in any server they join? I’m pretty sure you can just use a type of DataStore for this.
I’m trying to do any server. I’m aware that I would probably have to use data store and remote events. I’m just not entirely sure how I would do it.
This just feels like something you have to figure out how to make on your own, maybe someone else can help.
all i can say is make a PlayerAdded() function inside a server script, add ur DataStore then check if the player owns the model using the DataStore and just fire the RemoteEvent, then go into your client and Clone() the model from where ever you have it stored and parent it to the workspace
Could you give an example? Like is the model a house, a booth, etc?
Basically like just a tube thing which gives the player the in game currency which I can figure on my own. I’m trying to figure it out like a tycoon where you press the button and it spawns the model and saves.
Here’s what you’ll need to do:
-
Store the Model inside of ReplicatedStorage (You can use ServerStorage instead, if you’d like to hide the Model from the player. You can only access the Model using a server-side script, if using ServerStorage, but the benefit is that exploiters won’t be able to give the Model to themselves if they didn’t purchase it)
-
For each player, save a dictionary that uses the Model’s name as the index, and a number as the value
-
When the player joins the game, read the dictionary, and if the value that’s associated with the Model’s index is greater-than 0, clone the equivalent amount of Models from the storage service that you’re using, and give them to the player
so here is the base:
- When the player buys the model, you store info about that purchase (like the model’s name or ID) using a DataStore.
- When they rejoin, you check the DataStore to see if they bought anything.
- If they did, you spawn the model in the workspace just for them.
saving the Purchase on the server (maybe via a purchase script or GUI):
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("PurchasedModels")
game.Players.PlayerRemoving:Connect(function(player)
local ownedModels = {"CoolSword", "JetPack"} -- Example, update with what they own
myDataStore:SetAsync(player.UserId.."_Models", ownedModels)
end)
loading It Back In, when the player rejoins, on PlayerAdded
:
game.Players.PlayerAdded:Connect(function(player)
local ownedModels = myDataStore:GetAsync(player.UserId.."_Models") or {}
for _, modelName in pairs(ownedModels) do
local modelTemplate = game.ServerStorage.Models:FindFirstChild(modelName)
if modelTemplate then
local modelClone = modelTemplate:Clone()
modelClone.Parent = workspace
modelClone:SetPrimaryPartCFrame(player.Character:GetPrimaryPartCFrame() * CFrame.new(0, 5, 0))
end
end
end)
You’ll want to make sure your models are stored somewhere safe like ServerStorage
, and you’ll probably want to parent them into a folder in workspace
tagged with the player’s name so it’s easy to clean up when they leave.
Ah gotcha yeah that makes more sense. Yeah so lets say the player purchases it as a gamepass. You can change if the user owns the gamepass. If they do own it spawn the model. Additionally, if they buy it ingame you can use the prompt purchase to check if they bought it. I recommend you use Roblox’s method on their website.
If you want the entire tycoon save you’ll have to add a DataStore to it.
I’m not looking for it to be a gamepass. I’m just trying to figure out how to make it like a tycoon button, the player spends the in game currency, the model spawns, and it saves.
Okay yeah.
- So have the player data have all buttons as number values. Set them all to 0 since its a fresh start.
- When the player buys the button set the value to 1 (they own it).
- When the player leaves/joins set the data back to whatever the value was 0 or 1.
When they load back in and the value is 1, they own it, so make the model.
(This is a basic concept. But gets the idea passed)