Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Data Persistence not saving properly

Ok this script is supposed to load a Boolean from the player every time they die, when I change the boolean in game and then use a SaveBoolean on it it works when I respawn except that it doesn't teleport me like it is supposed to however when I rejoin the game the boolean is not how I saved it before I left. It always seems to get set to true when I saved it as false. The script is located inside a BoolValue that is inside the player's backpack.

Plr = script.Parent.Parent.Parent
b = script.Parent
Plr:WaitForDataReady()
if Plr:LoadBoolean("Jailed") and Plr:LoadString("JailReason") ~= nil then
	b.Value = Plr:LoadBoolean("Jailed")
elseif Plr:LoadBoolean("Jailed") == nil or Plr:LoadString("JailReason") == nil then
	Plr:SaveBoolean("Jailed", false)
	b.Value = false
	Plr:SaveString("JailReason", "")
end
if b.Value == true then
	Plr.Character:MoveTo(Workspace.Jailspawn.Position)
	Plr.Character.Humanoid.WalkSpeed = 5
	x = Plr.Backpack:GetChildren()
	for i = 1, #x do
		if x[i]:IsA("Tool") or x[i]:IsA("HopperBin") then
			x[i]:remove()
		end
	end
	z = Plr.Character:GetChildren()
	for i = 1, #z do
		if z[i]:IsA("Tool") then
			z[i]:remove()
		end
	end
	j = game.Lighting.JailedB:clone()
	j.Parent = Plr.Character.Head
	j.TextBox.Text = Plr:LoadString("JailReason")
end
function refresh ()
	Plr:SaveBoolean("Jailed", b.Value)
end
b.Changed:connect(refresh)

2 answers

This discussion is preserved as it was. New answers, comments, and votes are closed.