Custom datastore stat check not running script

I have a script in workspace that is meant to check if a player has a value set to true, but even if the player has the value set to true, the script still does not run for the player.

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Wait()
	if Player.Folder.BoolValue.Value == true then
       print("Success")
-- Run Script
end
end)

image
image

Does anybody know how to fix this?

Use a LocalScript instead and try this code:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

LocalPlayer.Folder.BoolValue.Changed:Connect(function()
    if LocalPlayer.Folder.BoolValue.Value == true then
        print("Success")
    end
end)

Is there a way to use your example without BoolValue.Changed?

The BoolValue does not change every time someone joins the game unless I’m misunderstanding something in your example.

Try this:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

if LocalPlayer.Folder.BoolValue.Value == true then
    print("Success")
end

Your solution does not appear to work.

Instead of: Player.CharacterAdded:Wait()

Try: Player.CharacterAdded:Connect(function(Character)

game.Players.PlayerAdded:Connect(function(Player)
	local Folder = Player:WaitForChild("Folder")
	local Bool = Folder:WaitForChild("BoolValue")
	Bool.Changed:Connect(function(NewBool)
		if NewBool then
			--Run code.
		end
	end)
end)

Your if conditional statement would only ever be checked once (for each player when they first join), you need to listen to the BoolValue’s “.Changed” event to detect when the value of its “Value” property changes.

This works, but is there a way to run this same solution when the player dies?

This Code:

Player.Character:WaitForChild("Humanoid").Died:Connect(function()
				wait(3.8)
				local Folder = Player:WaitForChild("Folder")
				local Bool = Folder:WaitForChild("BoolValue")
				Bool.Changed:Connect(function(NewBool)
					if NewBool then
                    -- Code

does not seem to work.

I’m just going to give someone else the benefit of assisting you.

I think I may have already found a solution myself.