Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rs = game:GetService("ReplicatedStorage");
- local ds = game:GetService("DataStoreService");
- local buxStore = ds:GetDataStore("Bux");
- local codesStore = ds:GetDataStore("Codes");
- local events = rs:WaitForChild("Events");
- local redeemFunction = events:WaitForChild("Redeem");
- local codes = {["topnotch"]=200};
- local cantUse = {};
- redeemFunction.OnServerInvoke = function(player, codeIn)
- local code = codeIn:lower();
- if (codes[code]) then
- local entry = codesStore:GetAsync(code);
- if (entry == nil) then
- codesStore:SetAsync(code,{});
- entry = {};
- end
- if (entry[player.UserId] == nil and cantUse[player.Name] == nil) then
- entry[player.UserId] = true;
- cantUse[player.Name] = true;
- coroutine.resume(coroutine.create(function()
- codesStore:SetAsync(code, entry);
- end))
- local add = codes[code];
- local stat = player:WaitForChild("leaderstats"):WaitForChild("PremierBux");
- stat.Value = stat.Value+add;
- return "Code applied successfully (+"..add..").";
- else
- return "Code already redeemed."
- end
- else
- return "Code invalid.";
- end
- end
- game.Players.PlayerAdded:Connect(function(player)
- local lStats = player:WaitForChild("leaderstats");
- local pBux = Instance.new("NumberValue");
- pBux.Name = "PremierBux";
- pBux.Parent = lStats;
- local value = buxStore:GetAsync(player.UserId);
- pBux.Value = value or 0;
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local lStats = player:WaitForChild("leaderstats");
- local pBux = lStats:waitForChild("PremierBux");
- buxStore:SetAsync(player.UserId, pBux.Value);
- end)
- game:BindToClose(function()
- for i,v in pairs(game.Players:GetChildren()) do
- local lStats = v:WaitForChild("leaderstats");
- local pBux = lStats:waitForChild("PremierBux");
- buxStore:SetAsync(v.UserId, pBux.Value);
- end
- end)
- while (true) do
- wait(60);
- for i,v in pairs(game.Players:GetChildren()) do
- local lStats = v:WaitForChild("leaderstats");
- local pBux = lStats:waitForChild("PremierBux");
- pBux.Value = pBux.Value+5;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement