(Potential Bug) Workspace clearing after data store scripts?

Hi guys, so I put two new scripts into my game today. One responds to a remote event in repstore, and the other runs on startup. Here’re the contents:
Leaderstats Script:
–bigcrazycarboy

local DataStore = game:GetService("DataStoreService")
local BankStore = DataStore:GetDataStore("SunFirstBankCoralCity")
local PocketStore = DataStore:GetDataStore("PlayerPocketCash")

game.Players.PlayerAdded:connect(function(newPlayer)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	
	if PocketStore:GetAsync(newPlayer.UserId) then
		cash.Value = PocketStore:GetAsync(newPlayer.UserId)
	else
		cash.Value = 500
		PocketStore:SetAsync(newPlayer.UserId, cash.Value)
	end

	cash.Parent = stats

	stats.Parent = newPlayer 
	
	if BankStore:GetAsync(newPlayer.UserId) then
		return
	else
		BankStore:SetAsync(newPlayer.UserId, 0)
	end	
	
	while true do
		wait(200)
		if newPlayer.TeamColor ~= BrickColor.new("Fossil") then
			cash.Value = cash.Value + 30
		end
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local cash = player:WaitForChild("leaderstats").Cash
	PocketStore:SetAsync(player.UserId, cash.Value)
	print("Saving Data for "..player.Name.." before they leave.")
end)

The next one is the event responder.
–bigcrazycarboy

local DataStore = game:GetService("DataStoreService")
local BankStore = DataStore:GetDataStore("SunFirstBankCoralCity")
local PocketStore = DataStore:GetDataStore("PlayerPocketCash")


game.ReplicatedStorage.RemoteEvents.BankMoney.OnServerEvent:connect(function(player, action, amount)
	if action == "Deposit" then
		local Money = BankStore:GetAsync(player.UserId)
		local NewMoney = Money + math.abs(amount)
		BankStore:SetAsync(player.UserId, NewMoney)
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - math.abs(amount)
		print("Deposited "..(math.abs(amount)).." into "..player.Name.."'s bank account.")
	elseif action == "Withdraw" then
		local Money = BankStore:GetAsync(player.UserId)
		local NewMoney = Money - math.abs(amount)
		if NewMoney > 0 then
			BankStore:SetAsync(player.UserId, NewMoney)
			player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + math.abs(amount)
			print("Withdrew "..(math.abs(amount)).." into "..player.Name.."'s bank account.")
		end
	end
end)
--[[
game.Players.PlayerAdded:connect(function(newPlayer)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = PocketStore:GetAsync(newPlayer.UserId) or 500

	cash.Parent = stats

	stats.Parent = newPlayer 

	while true do
		wait(200)
		if newPlayer.TeamColor ~= BrickColor.new("Fossil") then
			cash.Value = cash.Value + 30
		end
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local c = player.leaderstats.Cash
	PocketStore:SetAsync(player.UserId, c)
	print("Saving Data for "..player.Name.." before they leave.")
end)]]

For some reson this keeps on clearing everything in workspace. I have StudioAPI enabled. Hopefully someone can help, and excuse any grammar issues I’m tired. What am I doing wrong? Thanks!
-big

1 Like

So you’re saying the code you provided (effectively) does workspace:ClearAllChildren()?

That’s odd - are you sure it’s not another script? Is Workspace actually clearing, or is that just what the explorer shows?

1 Like

I mean, I don’t see how any of these could cause workspace to be cleared. Have you tried disabling scripts to determain what’s causing it? Because I honestly don’t think these two scripts would cause such a thing, unless I overlooked something.

1 Like

Use Ctrl+Shift+F and search for anything that uses :Destroy(), :remove(), :ClearAllChildren() and find any unknown script you might have.

The code you provided does not alter anything under the workspace so I seriously doubt that’s the issue.

1 Like

I have this issue aswell, just rename anything that’s named “part” in workspace to something different, I’m unaware to why this issue occurs but it’s been a common bug lately.

It doesn’t happen in real game servers, only in studio or a test server. But yes, the Workspace definitely clears and it would need to be because of one of these scripts. I didn’t have this problem until I inserted both of these scripts.

Figure out where the issue lies exactly - firstly disable one script to see if it’s the other that is causing the problem.

Then, once you’ve figured out what script has the issue, narrow it down further using breakpoints/commenting things out.

Did you install any plugins in the meantime?

If it doesn’t happen in a live server the most likely culprit is a misbehaving plugin, try disabling all of your plugins and see if it persists.