Grabbing a value from a folder inside of the player when they leave

Basically I’m trying to set up this job system which works for the most part except for the cleanup system. The cleanup system is supposed to go into a folder in replicated storage named “Jobs” and remove -1 value from the amount of workers currently in that job so it doesnt just fill up with players who left the game and make the jobs unjoinable.

Now that im looking at this I believe this error is because there is no space in the job name. :man_facepalming:

I’m currently getting this error and I’ve revised the code around 10 times but can’t figure out a solution.

PlayerData folder(The players job is inside of this)
image
image

Jobs Folder(Replicated storage, contains a list of all of the jobs in the server along with the amount of workers in the job)

image
image

Code:

game.Players.PlayerRemoving:Connect(function(Player)
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Jobs = ReplicatedStorage:FindFirstChild("Jobs")
	local PlayerData = Player:FindFirstChild("PlayerData")
	local PlayerJob = PlayerData.Job.Value
	local PlayerJobFolder = Jobs:FindFirstChild(PlayerJob)
	
	if PlayerJob ~= "Unemployed" then
		PlayerJobFolder.CurrentWorkers.Value = PlayerJobFolder.CurrentWorkers.Value - 1
	end
	
end)

Now that im looking at this I believe this error is because there is no space in the job name. :man_facepalming:

image
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.