BoolValue not changing to true from Script after player death/reset

Hey All,

In my game setup, under Player there is a “BoolValue” set to false at the game start. In the world, a red Part is placed, containing a Script to change the “BoolValue” to true when the red Part is touched by a player. Nearby, there is also a blue Part with a similar Script. This script will do the opposite and set the “BoolValue” back to false. When first playing the game, these Scripts work fine to change the “BoolValue” between true/false. However, after my player dies/resets walking over and touching the red Part won’t change the “BoolValue” to true. But, if I then touch the blue Part (which doesn’t change anything since the “BoolValue” is already false), and return to the red Part once more, the red Part Script will now change the “BoolValue” to true. I don’t know why the red Part Script isn’t initially able to change the “BoolValue” to true after death/reset. Why will it work after the blue Part has been touched? It’s not an issue of waiting for everything to reload because I’ve waited 2 minutes before touching the red Part and it won’t change the “BoolValue”. Any thoughts?

Here is the Script for the red Part:

local part = script.Parent

part.Touched:Connect(function(part)

	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local character = humanoid.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		print(player)  -- This always prints even when the next line won't execute properly, so I know the function is working
		player:FindFirstChild("Outside").Value = true  -- This is the "BoolValue" that won't update to true again, after player death/reset
	end
end)

Here is the blue Part Script, which is very similar:

local part = script.Parent

part.Touched:Connect(function(part)
	
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local character = humanoid.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		print(player)
		player:FindFirstChild("Outside").Value = false
	end
end)

Here’s a picture of the two parts. I can walk between them and watch the “BoolValue” value property change:

can you show us the script where you are creating the Outside bool value?

Are you sure the value isn’t already “true” when the player is dead? If this doesn’t solve your problem, are you able to send me a file of the issue so that I can try to replicate it?

Here is a simple version of the game reproducing the problem (see below for the game). I have a Script in ServerScriptService which is creating the “BoolValue” under Player. I have two parts added to the world with their own scripts. The red Part changes the BoolValue to true and the blue Part Script changes it back to false. Under the StarterGui is a ScreenGui and under that a Frame. Under the Frame is a LocalScript which is setting the BoolValue to false at the start of the game. In my actual game there is more stuff in the local script and I wanted to ensure that the BoolValue was set to False at the start of the game. I’ve tested this simple game I’ve attached. It reproduces the same problem. When you start the game you can open up the properties of the BoolValue under Player. You will see it change between true/false as you pass through the two parts. In my setup I’m dying/resting with the BoolValue set to true. I respawn and the BoolValue is back to false. All good. Now I run up to the red Part to change the BoolValue back to true…and nothing happens. If I touch the blue Part next, then back to the red Part, it will now change the BoolValue to true.

BoolValueProblem.rbxl (22.3 KB)

I tested the game and discovered the issue is that you are changing Outside's value from the client when you reset.

If you reset while Outside is true in Studio, switch from the Client view:

to the Server view:

You will see that Outside remains true. You need to listen for when the player respawns on the Server. I changed the script in ServerScriptService to do that for you:

function onPlayerEntered(player)
	
	-- Setup the stats that track for our variables
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local outside = Instance.new("BoolValue")
	outside.Name = "Outside"
	outside.Value = false
	outside.Parent = player
	
	
	player.CharacterAdded:Connect(function(character) -- Runs when player respawns
		outside.Value = false -- Resets outside
	end)
end

-- Connecting the function to in game events
game.Players.PlayerAdded:Connect(onPlayerEntered)
2 Likes

That was the issue! Dang, I spend so long trying to figure that out. Thanks a bunch for digging deeper there and finding the problem in my game. Your answer was insightful. That part of the game is now working as I’d hope. Thanks again!