Place 1 (lobby root):
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("Bronze")
local ds1 = dss:GetDataStore("Silver")
local ds2 = dss:GetDataStore("Purple")
local ds3 = dss:GetDataStore("Legion")
local ds4 = dss:GetDataStore("Afganistan")
game.Players.PlayerAdded:Connect(function(plr)
local plrUserId = plr.UserId
local medals = Instance.new("Folder",plr)
medals.Name = "Medals"
local bronze = Instance.new("BoolValue",medals)
bronze.Name = "BronzeStar"
local silver = Instance.new("BoolValue",medals)
silver.Name = "SilverStar"
local heart = Instance.new("BoolValue",medals)
heart.Name = "PurpleHeart"
heart.Value = false
local merit = Instance.new("BoolValue",medals)
merit.Name = "LegionOfMerit"
merit.Value = false
local ac = Instance.new("BoolValue",medals)
ac.Name = "AfghanistanCampaign"
ac.Value = false
local getSuccess,errorMessage = pcall(function()
bronze.Value = ds:GetAsync(plrUserId) or false
silver.Value = ds1:GetAsync(plrUserId) or false
heart.Value = ds2:GetAsync(plrUserId) or false
merit.Value = ds3:GetAsync(plrUserId) or false
ac.Value = ds4:GetAsync(plrUserId) or false
print("loaded")
end)
if not getSuccess then
warn(errorMessage)
end
while wait(30) do
local setSuccess,errorMessage = pcall(function()
ds:SetAsync(plrUserId,plr.Medals.BronzeStar.Value)
ds1:SetAsync(plrUserId,plr.Medals.SilverStar.Value)
ds2:SetAsync(plrUserId,plr.Medals.PurpleHeart.Value)
ds3:SetAsync(plrUserId,plr.Medals.LegionOfMerit.Value)
ds4:SetAsync(plrUserId,plr.Medals.AfghanistanCampaign.Value)
print("saved")
end)
if not setSuccess then
warn(errorMessage)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local plrUserId = plr.UserId
local setSuccess,errorMessage = pcall(function()
ds:SetAsync(plrUserId,plr.Medals.BronzeStar.Value)
ds1:SetAsync(plrUserId,plr.Medals.SilverStar.Value)
ds2:SetAsync(plrUserId,plr.Medals.PurpleHeart.Value)
ds3:SetAsync(plrUserId,plr.Medals.LegionOfMerit.Value)
ds4:SetAsync(plrUserId,plr.Medals.AfghanistanCampaign.Value)
print("saved")
end)
if not setSuccess then
warn(errorMessage)
end
end)
Place 2 (mission 1):
local ac = game:GetService("DataStoreService"):GetDataStore("Afghanistan")
workspace.AI.ChildRemoved:Connect(function()
if #workspace.AI:GetChildren() == 0 then
for i,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.RewardUI.Enabled = true
v.Character.HumanoidRootPart.Completion.Playing = true
ac:SetAsync(v.UserId,true)
wait(5)
v:Kick("Mission complete.")
end
end
end)
I am trying to get it so it saved the Afghanistan Campaign Medal to the datastore “Afghanistan” so that when they get to the main place it shows in their medal UI that they have the medal. It doesn’t work though, anybody know why?