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

Always Giving Back Error Message When Connecting?

Alright, so basically I'm making a basic save data thing. it's really simple. When you click a button, it saves that you clicked the button and the button will show as the clicked version of the button next time you boot up the game. The only issue I'm having (I did extensive research on how to fix it, and found nothing) is that I'm only getting the error message in return. This should explain it.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
local Ready = true

game.Players.PlayerAdded:Connect(function(plr)
	
	plr.Archivable = true
	
	
	local Account = Instance.new("BoolValue")
	Account.Parent = plr:FindFirstChild("PlayerGui")
	Account.Name = "Account"
	
	print(plr:FindFirstChild("PlayerGui").Account.Value)
	
	local data
	
	local success, errormessage = pcall(function()
		
		data = DataStore:GetAsync("Gamer"..plr.UserId)
		
	end)
	
	if success then
		
		plr.PlayerGui.Account.Value = true
		
		print("okay")
		
	else
		
		plr.PlayerGui.Account.Value = false
		
	end
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
		local success, errormessage = pcall(function()
		
		DataStore:SetAsync("Gamer"..plr.UserId,plr:FindFirstChild("PlayerGui").Account.Value)
		
		end)
	
	if success then
		
		print("Save Successful")
		
	end
	
	if errormessage then
		
		print("HKFBKWFHBKWHKFBHKWBFWJKFJWKBFKJBWJKFBKJWJKF")
		
	end
		
end)

Every time I leave the game it prints: "HKFBKWFHBKWHKFBHKWBFWJKFJWKBFKJBWJKFBKJWJKF"

Please help

1 comment

0

did you test it in studio?

1 answer

✓ Accepted answer

Here's a change I made to your code, it may even work better. This should fix the issue to your errors. I have worked on making sure this thing functions as well as it could.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local DataStorage = DataStoreService:GetDataStore("DataStore")

local LoadData = function(Player)
	if not Player or not Player:IsA("Player") then
		return
	end
	local PlayerGui = Player:FindFirstChildOfClass("PlayerGui")
	repeat
		wait()
	until PlayerGui ~= nil
	local BoolValue = Instance.new("BoolValue")
	BoolValue.Name = "Account"
	BoolValue.Parent = PlayerGui
	print(BoolValue.Value)
	local Success,Data = pcall(function()
		return DataStorage:GetAsync(("Gamer") .. Player.UserId)
	end)
	if Success then
		BoolValue.Value = true
	else
		BoolValue.Value = false	
	end
end

local SaveData = function(Player)
	if not Player or not Player:IsA("Player") then
		return
	end
	local Success,Value = pcall(function()
		local PlayerGui = Player:FindFirstChildOfClass("PlayerGui")
		repeat
			wait()
		until PlayerGui ~= nil
		DataStorage:SetAsync(("Gamer") .. Player.UserId,PlayerGui.Account.Value)
	end)
	if Success then
		print(":)")
	else
		print((typeof(Value) == "string" and Value) or tostring(Value))
	end
end

for _,Player in pairs(Players:GetPlayers()) do
	LoadData(Player)
end
Players.PlayerAdded:Connect(LoadData)
Players.PlayerRemoving:Connect(SaveData)

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