I want to be able to click a save button ingame, which saves the player's body color, and have a continue button, which (after a player dies and the continue button is clicked) loads the player's color.
Currently, I'm trying to use a table to do so, but that returns nil when continue is pressed. The script is a LocalScript under PlayerGui.
The script:
-- [[ Player ]] -- local player = game.Players.LocalPlayer repeat wait() until player.Character player.Character.Humanoid.WalkSpeed = 0 -- [[ Title Camera ]] -- local cam = workspace.CurrentCamera local CameraLocation1 = Vector3.new(-22.5, 35.5, -58.5) local CameraDirection1 = Vector3.new(-8, 4.5, -92) local titlecam = true cam.CameraType = "Scriptable" game["Run Service"].RenderStepped:connect(function() if titlecam == true then cam.CoordinateFrame = CFrame.new(CameraLocation1,CameraDirection1) end end) -- [[ Title Screen ]] -- local titlescreen = Instance.new("ScreenGui", script.Parent) titlescreen.Name = "Title Screen" -- Frame local titleframe = Instance.new("Frame", titlescreen) titleframe.Name = "Title Frame" titleframe.Position = UDim2.new(0.08, 0, 0.01, 0) titleframe.Size = UDim2.new(.85, 0, .85, 0) titleframe.Style = "RobloxRound" -- New Game titlebutton = Instance.new("TextButton", titlescreen) titlebutton.Name = "New Game" titlebutton.Position = UDim2.new(0.4, 0, 0.30, 0) titlebutton.Size = UDim2.new(0.25, 0, 0.1, 0) titlebutton.BackgroundColor3 = Color3.new(144, 0, 0) titlebutton.FontSize = "Size14" titlebutton.Text = "New Game" -- Continue Game titlebutton2 = Instance.new("TextButton", titlescreen) titlebutton2.Name = "Continue Game" titlebutton2.Position = UDim2.new(0.4, 0, 0.50, 0) titlebutton2.Size = UDim2.new(0.25, 0, 0.1, 0) titlebutton2.BackgroundColor3 = Color3.new(144, 0, 0) titlebutton2.FontSize = "Size14" titlebutton2.Text = "Continue Game" -- [[ Character Creation ]] -- local CharacterCreate = Instance.new("ScreenGui", script.Parent) CharacterCreate.Name = "Character Creation" local savegui = Instance.new("ScreenGui", script.Parent) savegui.Name = "Save" local CharacterCreateDone = Instance.new("TextButton", CharacterCreate) CharacterCreateDone.Name = "Done" CharacterCreateDone.Position = UDim2.new(0.9, 0, 0.9, 0) CharacterCreateDone.Size = UDim2.new(0.08, 0, 0.05, 0) CharacterCreateDone.BackgroundColor3 = Color3.new(144, 0, 0) CharacterCreateDone.FontSize = "Size12" CharacterCreateDone.Text = "Done" CharacterCreateDone.Visible = false local SaveButton = Instance.new("TextButton", savegui) SaveButton.Name = "Save Button" SaveButton.Position = UDim2.new(0.9, 0, 0.9, 0) SaveButton.Size = UDim2.new(0.08, 0, 0.05, 0) SaveButton.BackgroundColor3 = Color3.new(144, 0, 0) SaveButton.FontSize = "Size12" SaveButton.Text = "Save" SaveButton.Visible = false -- [ Body Colors ] -- -- Text local CharacterText = Instance.new("TextButton", CharacterCreate) CharacterText.Name = "Body Color Heading" CharacterText.TextColor3 = Color3.new(0, 0, 0) CharacterText.Position = UDim2.new(0.04, 0, 0.25, 0) CharacterText.Size = UDim2.new(0.1, 0, 0.05, 0) CharacterText.Font = "SourceSans" CharacterText.FontSize = "Size24" CharacterText.BackgroundTransparency = 1 CharacterText.Text = "Body Color" CharacterText.Visible = false -- Color Definitions local bc1 = BrickColor.new("Dark orange") local bc2 = BrickColor.new("Reddish brown") local bc3 = BrickColor.new("Pastel brown") local c1 = bc1.Color local c2 = bc2.Color local c3 = bc3.Color -- Buttons local cc1 = Instance.new("TextButton", CharacterCreate) cc1.Visible = false cc1.Name = "Dark Orange" cc1.Position = UDim2.new(0.04, 0, 0.35, 0) cc1.Size = UDim2.new(0.02, 0 , 0.04, 0) cc1.BackgroundColor3 = c1 cc1.Text = " " local cc2 = Instance.new("TextButton", CharacterCreate) cc2.Visible = false cc2.Name = "Reddish Brown" cc2.Position = UDim2.new(0.08, 0, 0.35, 0) cc2.Size = UDim2.new(0.02, 0 , 0.04, 0) cc2.BackgroundColor3 = c2 cc2.Text = " " local cc3 = Instance.new("TextButton", CharacterCreate) cc3.Visible = false cc3.Name = "Pastel Brown" cc3.Position = UDim2.new(0.12, 0, 0.35, 0) cc3.Size = UDim2.new(0.02, 0 , 0.04, 0) cc3.BackgroundColor3 = c3 cc3.Text = " " -- Camera local CameraLocation2 = Vector3.new(-29, 8, -95) local CameraDirection2 = Vector3.new(-29.015, 8.004, -72.534) local charactercam = false -- [[ MouseClicks ]] -- -- [ TitleButton MouseClicks ] -- function TB1click() titlescreen:Destroy() titlecam = false charactercam = true cam.CameraType = "Scriptable" game["Run Service"].RenderStepped:connect(function() if charactercam == true then cam.CoordinateFrame = CFrame.new(CameraLocation2,CameraDirection2) end end) -- CharacterFrame1.Visible = true CharacterText.Visible = true cc1.Visible = true cc2.Visible = true cc3.Visible = true CharacterCreateDone.Visible = true end function TB2click() titlescreen:Destroy() titlecam = false SaveButton.Visible = true cam.CameraSubject = player.Character.Humanoid cam.CameraType = "Custom" playercolor = (characterData[1]) player.Character.Humanoid.WalkSpeed = 16 if playercolor == "Dark orange" then player.Character.Head.BrickColor = BrickColor.new("Dark orange") player.Character.Torso.BrickColor = BrickColor.new("Dark orange") player.Character["Right Arm"].BrickColor = BrickColor.new("Dark orange") player.Character["Left Arm"].BrickColor = BrickColor.new("Dark orange") player.Character["Right Leg"].BrickColor = BrickColor.new("Dark orange") player.Character["Left Leg"].BrickColor = BrickColor.new("Dark orange") elseif playercolor == "Reddish brown" then player.Character.Head.BrickColor = BrickColor.new("Reddish brown") player.Character.Torso.BrickColor = BrickColor.new("Reddish brown") player.Character["Right Arm"].BrickColor = BrickColor.new("Reddish brown") player.Character["Left Arm"].BrickColor = BrickColor.new("Reddish brown") player.Character["Right Leg"].BrickColor = BrickColor.new("Reddish brown") player.Character["Left Leg"].BrickColor = BrickColor.new("Reddish brown") elseif playercolor == "Pastel brown" then player.Character.Head.BrickColor = BrickColor.new("Pastel brown") player.Character.Torso.BrickColor = BrickColor.new("Pastel brown") player.Character["Right Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Right Leg"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Leg"].BrickColor = BrickColor.new("Pastel brown") else player.Character.Head.BrickColor = BrickColor.new("Pastel brown") player.Character.Torso.BrickColor = BrickColor.new("Pastel brown") player.Character["Right Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Right Leg"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Leg"].BrickColor = BrickColor.new("Pastel brown") end end function TB3click() titlescreen:Destroy() end -- [ Body Color MouseClicks ] -- function c1Click() cc2.BorderColor3 = Color3.new(0, 0, 0) cc2.BorderSizePixel = 1 cc3.BorderColor3 = Color3.new(0, 0, 0) cc3.BorderSizePixel = 1 cc1.BorderColor3 = Color3.new(255, 255, 255) cc1.BorderSizePixel = 2 player.Character.Head.BrickColor = BrickColor.new("Dark orange") player.Character.Torso.BrickColor = BrickColor.new("Dark orange") player.Character["Right Arm"].BrickColor = BrickColor.new("Dark orange") player.Character["Left Arm"].BrickColor = BrickColor.new("Dark orange") player.Character["Right Leg"].BrickColor = BrickColor.new("Dark orange") player.Character["Left Leg"].BrickColor = BrickColor.new("Dark orange") playercolor = "Dark orange" end function c2Click() cc1.BorderColor3 = Color3.new(0, 0, 0) cc1.BorderSizePixel = 1 cc3.BorderColor3 = Color3.new(0, 0, 0) cc3.BorderSizePixel = 1 cc2.BorderColor3 = Color3.new(255, 255, 255) cc2.BorderSizePixel = 2 player.Character.Head.BrickColor = BrickColor.new("Reddish brown") player.Character.Torso.BrickColor = BrickColor.new("Reddish brown") player.Character["Right Arm"].BrickColor = BrickColor.new("Reddish brown") player.Character["Left Arm"].BrickColor = BrickColor.new("Reddish brown") player.Character["Right Leg"].BrickColor = BrickColor.new("Reddish brown") player.Character["Left Leg"].BrickColor = BrickColor.new("Reddish brown") playercolor = "Reddish brown" end function c3Click() cc1.BorderColor3 = Color3.new(0, 0, 0) cc1.BorderSizePixel = 1 cc2.BorderColor3 = Color3.new(0, 0, 0) cc2.BorderSizePixel = 1 cc3.BorderColor3 = Color3.new(255, 255, 255) cc3.BorderSizePixel = 2 player.Character.Head.BrickColor = BrickColor.new("Pastel brown") player.Character.Torso.BrickColor = BrickColor.new("Pastel brown") player.Character["Right Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Arm"].BrickColor = BrickColor.new("Pastel brown") player.Character["Right Leg"].BrickColor = BrickColor.new("Pastel brown") player.Character["Left Leg"].BrickColor = BrickColor.new("Pastel brown") playercolor = "Pastel brown" end function ccD() CharacterCreate:Destroy() charactercam = false SaveButton.Visible = true cam.CameraSubject = player.Character.Humanoid cam.CameraType = "Custom" player.Character.Humanoid.WalkSpeed = 16 end -- [ Save ] -- function save() characterData = { bodyColors = playercolor} print("Saved!") end -- MouseClick Connectors titlebutton.MouseButton1Down:connect(TB1click) titlebutton2.MouseButton1Down:connect(TB2click) titlebutton3.MouseButton1Down:connect(TB3click) cc1.MouseButton1Down:connect(c1Click) cc2.MouseButton1Down:connect(c2Click) cc3.MouseButton1Down:connect(c3Click) CharacterCreateDone.MouseButton1Down:connect(ccD) SaveButton.MouseButton1Down:connect(save)
Thanks in advance!
Well tables don't save so you would have to make a model that holds all variables you want to save, in the model it will be safe from reload until the player actually quits the game. In the model you can have defaults and stuff. And then on continue just make it reference the model.