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

Why is my Data persistence script not working?

I am trying to make it to where it will save a hat

If it were bought in a in-game store.

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady() 
plr.CharacterAdded:connect(function(usr)


local stats = Instance.new("IntValue")
stats.Name = "dist" 
local hat = Instance.new("BoolValue") 
hat.Name = "Dominus"
hat.Value = false

hat.Parent = stats 
stats.Parent = plr

if plr:LoadBoolean("A") then
	h = Instance.new("Hat")
	p = Instance.new("Part")
	h.Name = "HoodedAssassin"
	p.Parent = h
	p.Position = usr:findFirstChild("Head").Position
	p.Name = "Handle" 
	p.formFactor = 0
	p.Size = Vector3.new(1, 0.4, 1) 
	p.BottomSurface = 0 
	p.TopSurface = 0 
	p.Locked = true 
	mesh = Instance.new("SpecialMesh", p)
	mesh.MeshId = "http://www.roblox.com/asset/?id=21057410"
	h.Parent = usr
	h.AttachmentForward = Vector3.new (-0, -0, -1)
	h.AttachmentPos = Vector3.new(0, 0.4, 0)
	h.AttachmentRight = Vector3.new (1, 0, 0)
	h.AttachmentUp = Vector3.new (0, 1, 0)
else
	print("Player does not own this hat.")
end

end)
end)

game.Players.PlayerRemoving:connect(function(plyr)
plyr:SaveBoolean("A", plyr.leaderstats.hat.Value)
end)

1 answer

Things I spotted:

Line 42 will error because there's no object named "hat" in leaderstats. The object you created is named Dominus.

plyr:SaveBoolean("A", plyr.leaderstats.hat.Value)

Line 20 may also throw an error if the character's Head doesn't exist.

p.Position = usr:findFirstChild("Head").Position

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