Assigning Pager Channel

Hello, I am currently working on somewhat of a pager for a German Roleplay Group.

There are a total of four channels on the pager which each player should be assigned to as soon as they die or reset. I achieve that by using Character.Added:Connect(function(Character).

I have checked the team names and they do not seem to be the issue as they are properly named.

The rest of the script works it is just the following snippet, which is responsible for assigning a Player to the channel, does not even seem to work as I do not get the awaiting print message in the console.

Here is a list of what could be useful to know:

  • This script is a local script
  • Every other part of the script works perfectly fine
  • The script is located in the UI itself

Snippet:

local Player = game.Players.LocalPlayer
local AssignedChannel

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if player == Player then
			local teamName = Player.Team.Name

			if teamName == "Autobahnpolizei" or teamName == "Polizei" or teamName == "SEK" or teamName == "Zoll" or teamName == "Citizen" then
				AssignedChannel = "Polizei"
			elseif teamName == "Feuerwehr" or teamName == "THW" then
				AssignedChannel = "Feuerwehr"
			elseif teamName == "Rettungsdienst" then
				AssignedChannel = "Rettungsdienst"
			end

			print(AssignedChannel)
		end
	end)
end)

Thank you very much for looking into this. I appreciate any help!

Since it’s a local script you don’t need to do the player/character added events. do this at the top of your script:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local AssignedChannel
local teamName = Player.Team.Name

if teamName == "Autobahnpolizei" or teamName == "Polizei" or teamName == "SEK" or teamName == "Zoll" or teamName == "Citizen" then
	AssignedChannel = "Polizei"
elseif teamName == "Feuerwehr" or teamName == "THW" then
	AssignedChannel = "Feuerwehr"
elseif teamName == "Rettungsdienst" then
	AssignedChannel = "Rettungsdienst"
end

print(AssignedChannel)

Haven’t tested this out but it should work.

Thank you, I forgot I cannot use them in Local Scripts. That was clearly my mistake.

After a few modifications this is the code that now works:

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

local function HandleCharacterAdded(character)
	local teamName = Player.Team.Name

	if teamName == "Autobahnpolizei" or teamName == "Polizei" or teamName == "SEK" or teamName == "Zoll" or teamName == "Citizen" then
		AssignedChannel = "Polizei"
	elseif teamName == "Feuerwehr" or teamName == "THW" then
		AssignedChannel = "Feuerwehr"
	elseif teamName == "Rettungsdienst" then
		AssignedChannel = "Rettungsdienst"
	end

	print(AssignedChannel)
end

Player.CharacterAdded:Connect(HandleCharacterAdded)

local character = Player.Character
if character then
	HandleCharacterAdded(character)
end

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