I am trying to make a datastore that will save and apply an accessory and a sound to a character. There are no errors, but there is no mask or sound inside of the character model.
Script:
local DS = game:GetService("DataStoreService")
local RS = game:GetService("ReplicatedStorage")
local StatDataStore = DS:GetDataStore("StatData")
local HiddenDataStore = DS:GetDataStore("HiddenData")
local Masks = RS:WaitForChild("Masks")
local Sounds = RS:WaitForChild("ScareSounds")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Scares = Instance.new("NumberValue", leaderstats)
Scares.Name = "Scares"
local Money = Instance.new("NumberValue", leaderstats)
Money.Name = "Money"
local hiddendata = Instance.new("Folder", player)
hiddendata.Name = "hiddendata"
local Mask = Instance.new("NumberValue", hiddendata)
Mask.Name = "Mask"
local Sound = Instance.new("NumberValue", hiddendata)
Sound.Name = "Sound"
local statData
local hiddenData
local success, response = pcall(function()
statData = StatDataStore:GetAsync(player.UserId)
hiddenData = HiddenDataStore:GetAsync(player.UserId)
end)
Scares.Value = 0 or statData[1]
Money.Value = 0 or statData[2]
Mask.Value = 1 or hiddenData[1]
Sound.Value = 1 or hiddenData[2]
player.CharacterAdded:Connect(function(character)
local Mask2Clone = Masks:FindFirstChild(tostring(player.hiddendata.Mask.Value))
local Sound2Clone = Sounds:FindFirstChild(tostring(player.hiddendata.Sound.Value))
Mask2Clone:Clone().Parent = character
Sound2Clone:Clone().Parent = character:WaitForChild("Head")
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local statData = {player.leaderstats.Scares.Value, player.leaderstats.Money.Value}
local hiddenData = {player.hiddendata.Mask.Value, player.hiddendata.Sound.Value}
local success, response = pcall(function()
StatDataStore:SetAsync(player.UserId, statData)
HiddenDataStore:SetAsync(player.UserId, hiddenData)
end)
end)