Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- // Variables
- local Codes = require(game.ServerScriptService.Codes)
- local Player = script.Parent.Parent.Parent.Parent.Parent
- local GetInput = script.Parent.Parent.GetInput
- local SendNotification = GetInput.Parent.SendNotification
- -- // Cooldown
- local Cooldown = 1
- local now = tick()
- --
- -- // Get player data
- local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData")
- local Player_ID = "Player_" .. Player.UserId
- local Data
- local Success,err = pcall(function()
- Data = Datastore:GetAsync(Player_ID)
- end)
- if not Success then error(err) end
- if not Data then
- Data = {RedeemedCode = {}}
- end
- ---
- -- // Function
- local function mouseClick()
- if tick() - now <= Cooldown then return end
- local input = GetInput:InvokeClient(Player)
- now = tick()
- if Codes[input] then
- if not table.find(Data.RedeemedCode,input) then
- table.insert(Data.RedeemedCode,input)
- coroutine.wrap(Codes[input])(Player)
- SendNotification:FireClient(Player,{Title = "Congratulations"; Text = "Code redeemed"})
- local success,err = pcall(Datastore.UpdateAsync,Datastore,Player_ID,function(old)
- return Data
- end)
- if not success then error(err) end
- else
- SendNotification:FireClient(Player,{Title = "Error"; Text = "Code already redeemed"})
- end
- else
- SendNotification:FireClient(Player,{Title = "Error"; Text = "Invalid Code"})
- end
- end
- --
- -- // Bind event
- script.Parent.MouseButton1Down:Connect(mouseClick)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement