Advertisement
SxScripting

Race System Script

Mar 13th, 2021
8,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. -- Subscribe to SxS Scripting For More!
  2.  
  3. local DataSaving = game:GetService("DataStoreService"):GetDataStore("Saving1")
  4.  
  5. game.Players.PlayerAdded:Connect(function(Player)
  6. local Character = Player.Character or Player.CharacterAdded:Wait()
  7. local Humanoid = Character:WaitForChild("Humanoid")
  8. local PlayerGui = Player:WaitForChild("PlayerGui")
  9.  
  10. local Races = {
  11. Human = 60,
  12. Demon = 5,
  13. Elf = 20,
  14. Giant = 40;
  15. }
  16.  
  17. local sum = 0
  18. for _,Values in pairs(Races) do
  19. sum = sum + Values
  20. end
  21.  
  22. local function getRandomItem()
  23. local RaceValue = Random.new():NextNumber(0, sum)
  24. for item, value in pairs(Races) do
  25. RaceValue = RaceValue - value
  26. if RaceValue < 0 then
  27. return item
  28. end
  29. end
  30. end
  31.  
  32.  
  33. local function ChangeBody()
  34. local RaceNames = Player.DataFolder.Race.Value
  35.  
  36. local Parts = Character:GetChildren()
  37. local BodySizeParts = {
  38. Humanoid.HeadScale,
  39. Humanoid.BodyDepthScale,
  40. Humanoid.BodyWidthScale,
  41. Humanoid.BodyHeightScale,
  42. }
  43.  
  44. if RaceNames == "Giant" then
  45. for _,v in pairs(BodySizeParts) do
  46. v.Value = v.Value * 2
  47. end
  48. elseif RaceNames == "Elf" then
  49. for _,v in pairs(BodySizeParts) do
  50. v.Value = v.Value / 2
  51. end
  52. elseif RaceNames == "Demon" then
  53. for _,v in ipairs(Parts) do
  54. if v:IsA("BasePart") then
  55. v.BrickColor = BrickColor.new("Really black")
  56. end
  57. end
  58. end
  59.  
  60. end
  61.  
  62. local DataFolder = Instance.new('Folder',Player)
  63. DataFolder.Name = "DataFolder"
  64.  
  65. local Race = Instance.new("StringValue", DataFolder)
  66. Race.Name = "Race"
  67.  
  68. local function Change()
  69. PlayerGui.RaceDisplay.TextButton.Text = "Race: "..Race.Value
  70. end
  71.  
  72. local Success, Value = pcall(function()
  73. return DataSaving:GetAsync(Player.UserId)
  74. end)
  75.  
  76. if Success then
  77. if Value then
  78. Race.Value = Value[1]
  79. else
  80. Race.Value = tostring(getRandomItem())
  81. end
  82. else
  83. Race.Value = tostring(getRandomItem())
  84. end
  85.  
  86. ChangeBody()
  87. Change()
  88. end)
  89.  
  90. game.Players.PlayerRemoving:Connect(function(Player)
  91. local Success, Err = pcall(function()
  92. DataSaving:SetAsync(Player.UserId, {Player.DataFolder:WaitForChild('Race').Value})
  93. end)
  94. end)
  95.  
  96. game:BindToClose(function()
  97. for i, player in pairs(game.Players:GetPlayers()) do
  98. local Success, Err = pcall(function()
  99. DataSaving:SetAsync(player.UserId, {player.DataFolder:WaitForChild('Race').Value})
  100. end)
  101. end
  102. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement