How to stop my mission script from resetting upon player death

Hey All,

I’m attempting to figure out how to create a single mission for a player to complete. The problem is the mission is no longer active once the player dies. How can I make the mission stay active, even after player death?

The setup: The player goes up to an NPC, has a conversation, an ACCEPT button appears, the player clicks the button. The script, Mission1Script, detects the ACCEPT button being activated and makes the Mission GUI appears on the screen showing how many items they player has collected, makes cans of soda appear around the map for the player to pick up, and changes the color of the exclamation point above the NPC’s head to orange once all 10 sodas are picked up…

It seems to me that the it’s the Mission1Script that resets. I don’t see an option in the Script properties, like ResetOnSpawn, that I could uncheck. I’m assuming there’s something to be added to this script. Any suggestions?

Here is a copy of the Mission1Script for reference, if needed:

-- Variables

local textButton = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerName = Players.LocalPlayer.Name
local sodaNumber = 0
local debounce = true
local missionGui = script.Parent.Parent.Parent:WaitForChild("MissionGui")

missionGui.Enabled = false

-- Functions

local sodas = game.Workspace.Drinks:GetChildren()

for _, drink1 in pairs(sodas) do
	drink1.Transparency = 1
end

textButton.Activated:Connect(function()

local hum = player.Character:FindFirstChild("Humanoid")
local char = player.Character
local charName = char.Name
missionGui.Enabled = true
			
if hum and playerName == charName and debounce then
	
	debounce = false
	
	for _, drink in pairs(sodas) do
		   local canPickup = drink.Value.Value
		drink.Transparency = 0
			
			drink.Touched:Connect(function(part)
				local hum = part.Parent:FindFirstChild("Humanoid")
				local char = part.Parent
				local charName = char.Name
				
				if hum and playerName == charName and canPickup then
					canPickup = false
					drink.Transparency = 1
					sodaNumber = sodaNumber + 1
					missionGui.Frame.SodaLabel.Text = "Drinks: " .. sodaNumber 
			    end
			
			if sodaNumber == 10 then
			--	missionCompleted = true
				missionGui.Mission1CompletedValue.Value = true
				missionGui.Frame.SodaLabel.BackgroundColor3 = Color3.fromRGB(17,255,32)
				script.Parent.Parent.MissionValue.Value = "Lines2"
				game.Workspace.Exclamations.ToDaExclamation.Part1.BrickColor = BrickColor.new("Deep orange")
				game.Workspace.Exclamations.ToDaExclamation.Part2.BrickColor = BrickColor.new("Deep orange")
				
				end
			end)
		end
	end

end)

1 Like

Just put it somewhere that doesn’t reset upon player death. StarterPlayerScripts, for example, is a good place to put this script

3 Likes

I like that plan. I attempted to put the script into ServerScriptService…but Mission1Script is a LocalScript and my understanding is that LocalScripts don’t run in ServerScriptService. So I attempted to transfer the Mission1Script contents over into a Script. The issue I’m realizing is with the new Script, any change created by a player clicking the ACCEPT button will now produce changes for all players in the game, because I’m using a Script, instead of a LocalScript. Any further suggestion for how to keep the script local but not reset upon player death? Are there other safe locations (like ServerScriptService) where a LocalScript won’t reset?

1 Like

Just a tip, if you’re still trying to keep it a server script so it doesn’t effect everyone, there are work arounds, for example, your boolean sets everyones to true and false but if you do this

local Boolean = {} -- make a table to store player and values
if Boolean[Player] = true then
return
end
Boolean[Player] = false
if something something = something then
Boolean[Player] = true
delay(5, function()
Boolean[Player] = false
end)
end

Yes lol I literally told you. You can use StarterPlayerScripts (located in StarterPlayer). (:

Oh man, thanks for pointing out the obvious. When I read your previous reply, my brain read ServerScriptService, instead of what you actually wrote (StarterPlayerScripts). I’ll give it a shot!

1 Like

It worked as you suggested. I placed the LocalScript from the StarterGui into the StarterPlayerScripts and now mission is working. You’re suggestion also solved another problem. Some of the StringValues I had created in the StarterGui were losing their updated string values as well. Placing them into the StarterPlayerScripts keeps the updated string values from reverting back to the starting string. Thanks!

1 Like