Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Checking a team with a normal script?

so im trying to give the player money every 5 minutes via the server so it will save.

This is the error i get:   19:00:28.220 ServerScriptService.Leaderboard:26: attempt to index nil with 'Team'  -  Server  -  Leaderboard:26

this is the script i use:

local Player = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

while wait(300) do
	if Player.Team == Teams.Citizen then
		game.Players.LocalPlayer.Leaderboard.Money.Value = game.Players.LocalPlayer.Leaderboard.Money.Value + 10
	end
end

1 answer

Place a Remote Event in the local script, (Maybe Put it in StarterCharacterScripts?)

local Player = game:GetService("Players").LocalPlayer

while wait(300) do
	if Player.Team.Name == "Citizen" then
		game.ReplicatedStorage.RemoteEvent:FireServer(Player) --Make a remote event thats inside replicatedstorage
	end
end
		

ServerScript Placed in ServerScriptService,

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
	Player.Leaderboard.Money.Value = Player.Leaderboard.Money.Value + 10
end)

if this doesnt work then tell me

2 comments

0

The error is that with "Player.Team.Name" there is a error: Attempt to index nil with Team

0

then maybe do the teamcolor instead of the name, like if Player.Team.TeamColor == "Color" then

This discussion is preserved as it was. New answers, comments, and votes are closed.