Paycheck System is not working!

Server script:

local TeamsService = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local cashDataStore = DataStoreService:GetDataStore("CashData")

local EnabledTeams = {
	["team1"] = 100,
	["team2"] = 20
}

game.ReplicatedStorage.ClaimPaycheckEvent.OnServerEvent:Connect(function(player)
	local team = TeamsService:GetCurrentTeam(player)
	if team and EnabledTeams[team.Name] then
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local cash = leaderstats:FindFirstChild("Cash")
			if cash then
				cash.Value += EnabledTeams[team.Name]
			end
		end
	end
end)

ReplicatedStorage.GetCurrentTeam.OnServerEvent:Connect(function(player)  
	local team = TeamsService:GetCurrentTeam(player) 
	ReplicatedStorage.GetCurrentTeam:FireClient(player, team) 
end)

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats

	-- DataStore Loading
	local success, savedCash = pcall(function()
		return cashDataStore:GetAsync(player.UserId)
	end)

	if success and savedCash then
		cash.Value = savedCash
	else
		cash.Value = 0 -- Initial value if no data is found
	end
end)

Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		cashDataStore:SetAsync(player.UserId, player.leaderstats.Cash.Value)
	end)

	if not success then
		warn("Error saving data:", errorMessage)
	end
end)

Localscript:

local PaycheckScreen = script.Parent.Parent.Paycheck
local User = game.Players.LocalPlayer.Name
local Team = "" -- Initialize Team if unknown initially
local Amount = script.Parent.amount
local RemoteEvent = game.ReplicatedStorage.ClaimPaycheckEvent
local Interval = 5 -- Adjust as needed (seconds)


local RemoteEvent = game.ReplicatedStorage.GetCurrentTeam -- Assuming a RemoteEvent in ReplicatedStorage

local function checkTeamEligibility()
	RemoteEvent:FireServer() -- Request the team information from the server
end

RemoteEvent.OnClientEvent:Connect(function(team)
	if team then
		PaycheckScreen.Enabled = true
	else
		PaycheckScreen.Enabled = false
	end
end)



PaycheckScreen.claim.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer() 
	PaycheckScreen.Enabled = false 
end)


-- Update Amount (If necessary)
script.Parent.Changed:Connect(function(property)
	if property == "amount" then
		Amount = script.Parent.amount
	end
end)

-- Initial eligibility check and regular updates
checkTeamEligibility() 
while wait(Interval) do
	checkTeamEligibility()
end

GetCurrentTeam is not a valid member of Teams “Teams” - Server - Script:27

So I got this error. Not sure why specifically on this line, not sure how to fix it.
I made my code as organized as possible, and made a few notes.
Anyone know a solution?

You need to explain what’s not working, not dump the entire script for us to decode.

My bad, it seems the serverscript isn’t working.
It’s coming from line 27 as said. and I’m not sure why…

1 Like

Nah you’re good, i was just angry for no reason, my bad.

Try turning GetCurrentTeam into a variable?

local TeamsService = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local cashDataStore = DataStoreService:GetDataStore("CashData")

local EnabledTeams = {
	["team1"] = 100,
	["team2"] = 20
}

game.ReplicatedStorage.ClaimPaycheckEvent.OnServerEvent:Connect(function(player)
	local team = plr.Team
	if team and EnabledTeams[team.Name] then
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local cash = leaderstats:FindFirstChild("Cash")
			if cash then
				cash.Value += EnabledTeams[team.Name]
			end
		end
	end
end)

ReplicatedStorage.GetCurrentTeam.OnServerEvent:Connect(function(player)  
	local team = plr.Team
	ReplicatedStorage.GetCurrentTeam:FireClient(player, team) 
end)

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats

	-- DataStore Loading
	local success, savedCash = pcall(function()
		return cashDataStore:GetAsync(player.UserId)
	end)

	if success and savedCash then
		cash.Value = savedCash
	else
		cash.Value = 0 -- Initial value if no data is found
	end
end)

Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		cashDataStore:SetAsync(player.UserId, player.leaderstats.Cash.Value)
	end)

	if not success then
		warn("Error saving data:", errorMessage)
	end
end)

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