Im trying to make a datastore. I know that this script works, but when i go to make it save a different value, it errors out and i have no idea. Why?
local currencyName = "Company1PromotionCurrent"
local DataStore = game:GetService("DataStoreService"):GetDataStore("Company1PromotionCurrent")
game.Players.PlayerAdded:Connect(function(player)
wait(1)
local currency = player:WaitForChild("PlayerValues"):WaitForChild("OtherValues"):WaitForChild("CompanyValues"):WaitForChild("PromotionCurrent").Value
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.PlayerValues.OtherValues.CompanyValues:FindFirstChild("PromotionCurrent").Value)
end)
