Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I get this script to repeat each time the character respawns?

Asked by 7 years ago

I tried doing the CharacterAdded function but it had error

local DataStore = game:GetService("DataStoreService")
local Ds1 = DataStore:GetDataStore("Characters")
game.Players.PlayerAdded:connect(function(Player)
    Player:WaitForChild("Backpack") 

          local Gstuff = Instance.new("Folder",Player.Backpack)
          Gstuff.Name = "Gamestuff"
          local Chars = Instance.new("Folder",Gstuff)
          Chars.Name = "Characters"
         local Create = Instance.new("Folder",Chars)
          Create.Name = "Folder"
        local NumChars = Instance.new("IntValue",Chars)
          NumChars.Name = "Number"
         local BodyColors = Instance.new("BrickColorValue",Create)
               BodyColors.Name = "BColors"
               BodyColors.Value = BrickColor.new("Brick yellow")
         local HairColor = Instance.new("BrickColorValue",Create)
               HairColor.Name = "HairColor"
               HairColor.Value = BrickColor.new("Buttermilk")
         local HairId = Instance.new("StringValue",Create)
               HairId.Name = "HairId"
               HairId.Value = "Bald"
         local Shirt = Instance.new("StringValue",Create)
               Shirt.Name = "Shirt"
         local Pants = Instance.new("StringValue",Create)
               Pants.Name = "Pants"
         local Face = Instance.new("StringValue",Create)
               Face.Name = "Face"
               Face.Value = "rbxassetid://167133081"
         local Gender = Instance.new("StringValue",Create)
               Gender.Name = "Gender"
               Gender.Value = "Male"
         local Class = Instance.new("StringValue",Create)
               Class.Name = "Class"
               Class.Value = "None"
         local Exp = Instance.new("IntValue",Create)
               Exp.Name = "Exp"
               Exp.Value = 0
        local MaxExp = Instance.new("IntValue",Create)
               MaxExp.Name = "MaxExp"
              MaxExp.Value = 100
          local Level = Instance.new("IntValue",Create)
               Level.Name = "Level"
               Level.Value = 0
         local Zeni = Instance.new("IntValue",Create)
               Zeni.Name = "Zeni"
               Zeni.Value = 0

     local key = "Player-"..Player.userId
     local SavedValues = Ds1:GetAsync(key)

     if SavedValues then
        --Save Format -- {BodyColors,HairColor,HairId,Shirt,Pants,Face,Gender,Class,Level,NumChars,Zeni,Exp}
        BodyColors.Value = BrickColor.new(SavedValues[1])
        HairColor.Value = BrickColor.new(SavedValues[2])
        HairId.Value = SavedValues[3]
        Shirt.Value = SavedValues[4]
        Pants.Value = SavedValues[5]
        Face.Value = SavedValues[6]
        Gender.Value = SavedValues[7]
        Class.Value = SavedValues[8]
        Level.Value = SavedValues[9]
        NumChars.Value = SavedValues[10]
        Zeni.Value = SavedValues[11]
        Exp.Value = SavedValues[12]
        MaxExp.Value = SavedValues[13]
    else 
        local ValuesToSave = {BodyColors.Value.Name,HairColor.Value.Name,HairId.Value,Shirt.Value,
        Pants.Value,Face.Value,Gender.Value,Class.Value,Level.Value,NumChars.Value,Zeni.Value,Exp.Value,MaxExp.Value}
        Ds1:SetAsync(key, ValuesToSave)
    end
    Player.PlayerGui.Game.Health.ImageLabel.LevelNum.Text = Level.Value
    Player.PlayerGui.Game.Health.Currentlvl.Text = Level.Value
    Player.PlayerGui.Game.Health.Currentlvl.NextLvl.Text = Level.Value + 1
    Player.PlayerGui.Game.Health.ExpBar:TweenSize(UDim2.new(0.95*Exp.Value/MaxExp.Value,0,0,12), "Out", "Quart", 0.5, true)
    end)

Answer this question