Basically just trying to add a certain amount to the players Credits every 5 minutes depending on the players job. I’m getting an error that says Attempt to perform arithmetic(add) on nil and number.
When the 5 minutes is up and the timers value is set to 0 its supposed to add credits to the player based on the amount of income their job provides.
local PaycheckWaitTime = 300--(5 minutes)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage.Events
while wait(1) do
local PlayerData = Player:FindFirstChild("PlayerData")
local PlayerStats = Player:FindFirstChild("PlayerStats")
local PlayerJob = PlayerData.Job.Value
local PlayerJobFolder = ReplicatedStorage.Jobs:FindFirstChild(PlayerJob)
local Amount = ReplicatedStorage.Jobs:FindFirstChild(PlayerJobFolder.Salary.Value)
PaycheckTime.Value = PaycheckTime.Value - 1
if PaycheckTime.Value == 0 then
PlayerStats.Credits.Value = PlayerStats.Credits.Value +Amount
PaycheckTime.Value = PaycheckWaitTime
end
end
end)
In this case, if I chose the farmer job, I should be making $45 every 5 minutes.
50 is the salary for the job I chose
500 is the amount of credits I currently have. The error is no longer showing but its not adding to the amount of credits.
Updated Code:
local PaycheckWaitTime = 300--(5 minutes)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage.Events
while wait(1) do
local PlayerData = Player:FindFirstChild("PlayerData")
local PlayerStats = Player:FindFirstChild("PlayerStats")
local PlayerJob = PlayerData.Job.Value
local PlayerJobFolder = ReplicatedStorage.Jobs:FindFirstChild(PlayerJob)
local Amount = PlayerJobFolder.Salary.Value
PaycheckTime.Value = PaycheckTime.Value - 1
if PaycheckTime.Value == 0 then
print(Amount)
print(PlayerStats.Credits.Value)
PlayerStats.Credits.Value = PlayerStats.Credits.Value +Amount
PaycheckTime.Value = PaycheckWaitTime
end
end
end)
local PlayerJobFolder = ReplicatedStorage.Jobs:FindFirstChild(PlayerJob)
local Amount = ReplicatedStorage.Jobs:FindFirstChild(PlayerJobFolder.Salary.Value)
The paycheck is now working, the error was in the Amount.
Updated Code:
local PlayerJobFolder = ReplicatedStorage.Jobs:FindFirstChild(PlayerJob)
local Amount = PlayerJobFolder.Salary.Value