You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
The code that i have used is a character shop which works. The characters can be purchased and equipped. I want to save the players current equipped character (whole rigged and animated body) in my lobby so that when they leave the game then come back to play they load in as their last equipped character - including spawning into my other in-game places to play the games after teleporting off my lobby. Can someone help me what to write and where please? I will really appreciate your help. -
What is the issue? Include screenshots / videos if possible!
Im new to scripting and understand data stores at beginners level but cant seem to make/incorporate the equipped character (newCharacter)-data -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Ive tried to make equipped character (newCharacter) into data to save but failed. Ive checked the Dev hub, google and my scripting book but cant find anything to help guide me.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local replicatedStorage = game:GetService("ReplicatedStorage")
local DatastoreService = game:GetService("DataStoreService") ---data store
local Players = game:GetService("Players")
local datastore = DatastoreService:GetDataStore("MyDataStore") --data store
local characterShop = replicatedStorage.CharacterShop
local characters = characterShop.Characters
local remotes = characterShop.Remote
--i think this is the leaderstats
game.Players.PlayerAdded:Connect(function(player)
local characterShop = Instance.new("Folder")
characterShop.Name = "CharacterShop"
characterShop.Parent = player
local ownedCharacters = Instance.new("Folder")
ownedCharacters.Name = "Characters"
ownedCharacters.Parent = characterShop
local equippedCharacter = Instance.new("StringValue")
equippedCharacter.Name = "EquippedCharacter"
equippedCharacter.Value = "nil"
equippedCharacter.Parent = characterShop
local _characters = nil
local success, err = pcall(function()
_characters = datastore:GetAsync(player.UserId.."Characters")
end)
if _characters == nil then return end
if success and _characters ~= nil then
for i, v in pairs(_characters) do
local newVal = Instance.new("StringValue")
newVal.Name = v
newVal.Parent = ownedCharacters
end
else
warn(err)
end
end)
---up to here
local function playerRemoving(player)
local _characters = {}
local success, err = pcall(function()
for i, v in pairs(player.CharacterShop.Characters:GetChildren()) do
table.insert(_characters, v.Name)
end
datastore:SetAsync(player.UserId.."Characters", _characters)
end)
wait(6)
if success then
print("Success")
else
warn(err)
end
end
---or ends here
remotes.Buy.OnServerInvoke = function(player, tempName)
local character = characters:FindFirstChild(tempName)
if character == nil then return end
local price = character.Price.Value
local currentChar = player.Character
local pos = currentChar.PrimaryPart.CFrame
if player.CharacterShop.Characters:FindFirstChild(character.Name) and player.CharacterShop.EquippedCharacter.Value == character.Name then
return "Character Already Equipped"
elseif player.CharacterShop.Characters:FindFirstChild(character.Name) and player.CharacterShop.EquippedCharacter.Value ~= character.Name then
local newCharacter = character:Clone()
newCharacter.Name = player.Name
player.Character = newCharacter
newCharacter.Parent = workspace
newCharacter.PrimaryPart.CFrame = pos
return "Equip"
elseif not player.CharacterShop.Characters:FindFirstChild(character.Name) and player.CharacterShop.EquippedCharacter.Value ~= character.Name then
if tonumber(player.leaderstats[character.Currency.Value].Value) >= tonumber(price) then
player.leaderstats[character.Currency.Value].Value -= price
local charcterVal = Instance.new("StringValue")
charcterVal.Name = character.Name
charcterVal.Parent = player.CharacterShop.Characters
local newCharacter = character:Clone()
newCharacter.Name = player.Name
player.Character = newCharacter
newCharacter.Parent = workspace
newCharacter.PrimaryPart.CFrame = pos
return "Buy"
else
return "Failed"
end
end
end
Players.PlayerRemoving:Connect(playerRemoving)
game:BindToClose(function()
wait(6)
for i, v in pairs(Players:GetPlayers()) do
playerRemoving(v)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.