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.
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)
Jobs Folder(Replicated storage, contains a list of all of the jobs in the server along with the amount of workers in the job)
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)