Basically it’s like data service/store but i want to save a model to the player so when he rejoins he has the model on his character.
Sorry if you didn’t understand i don’t know english that much.
1 Like
Saving a Model to a Player’s Character
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("PlayerModels")
game.Players.PlayerAdded:Connect(function(player)
local model = Instance.new("Model")
local success, data = pcall(function()
return myDataStore:GetAsync(player.UserId)
end)
if success and data then
model = game.ServerStorage[data]:Clone()
end
model.Parent = player.Character
end)
game.Players.PlayerRemoving:Connect(function(player)
local characterModel = player.Character:FindFirstChildOfClass("Model")
if characterModel then
local success, err = pcall(function()
myDataStore:SetAsync(player.UserId, characterModel.Name)
end)
if not success then
warn(err)
end
end
end)
This script uses Roblox’s DataStoreService
to save and load the name of the model associated with a player’s character. When a player joins the game, the script checks if there is any saved data for that player. If there is, it loads the corresponding model from ServerStorage
and parents it to the player’s character. When a player leaves the game, the script saves the name of the model that is currently parented to their character.
1 Like