Advertisement
killerbrenden

Actor BindToClose

Dec 16th, 2020
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. if script.Parent:IsA("Actor") then
  2.   local bindable = script.Parent.Parent:WaitForChild("Bindable")
  3.  
  4.   local playerToSave
  5.   local connection
  6.  
  7.   connection = bindable.Event:Connect(function(player)
  8.     if player.Name == script.Parent.Name then
  9.       playerToSave = player
  10.       connection:Disconnect()
  11.       connection = nil
  12.     end
  13.   end)
  14.  
  15.   task.desynchronize()
  16.  
  17.   local tries = 0
  18.   local max = 5
  19.  
  20.   repeat wait(6)
  21.     local s, e = pcall(function()
  22.       DS:SetAsync(UUID, player.Data)
  23.     end)
  24.     tries += 1
  25.   until s or tries >= max
  26.  
  27.   task.synchronize()
  28. end
  29.  
  30. game:BindToClose(function()
  31.   if script.Parent:IsA("Actor") then return end
  32.  
  33.   local bindable = Instance.new("BindableEvent")
  34.   bindable.Name = "Bindable"
  35.   bincable.Parent = script
  36.  
  37.   for _,player in pairs(game:GetService("Players"):GetPlayers()) do
  38.     local actor = Instance.new("Actor")
  39.     actor.Name = player.Name
  40.  
  41.     script:Clone().Parent = Actor
  42.  
  43.     actor.Parent = script
  44.  
  45.     bindable:Fire(player)
  46.   end
  47. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement