How to save a GUI change?

I have a script that does this for a quest system (pay attention to the main frame in the video):

How can I make it so that once the player hits the part and the “X” changes into a “check mark,” it saves that and it is always a checkmark for the player whenever they leave and rejoin? Think of it as a quest system, and once the player completes the quest it should stay that way.

Below are the code I used to create this:
(code for the “X” to dissappear)

local part = game.Workspace.questmesh

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	local player = game.Players:GetPlayerFromCharacter(partParent)
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and player then
		local customframe = player:WaitForChild("PlayerGui"):WaitForChild("questgui").Frame.X
		-- Do something to the humanoid, like set its health to 0
		customframe.Visible = false
	end
end

part.Touched:Connect(onPartTouched)

(code for the “check mark” to appear)

local part = game.Workspace.questmesh

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	local player = game.Players:GetPlayerFromCharacter(partParent)
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and player then
		local customframe = player:WaitForChild("PlayerGui"):WaitForChild("questgui").Frame.check
		-- Do something to the humanoid, like set its health to 0
		customframe.Visible = true
	end
end

part.Touched:Connect(onPartTouched)

You need to use the DataStore to save state specific to a player’s UserId. Then the next time they join the game, you retrieve the data store values.

Data Stores (roblox.com)

2 Likes