GetPropertyChangedSignal not detecting

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    a print every time a player s Teamcolor changes

  2. What is the issue? Include screenshots / videos if possible!
    robloxapp-20211022-1652372.wmv (2.0 MB)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    TeamColor instead of Team does not anymore

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local md = require(game.ReplicatedStorage:WaitForChild("LevelModuleScript"))
game.Players.PlayerAdded:Connect(function(player)
	player:GetPropertyChangedSignal('Team'):Connect(function()
		print(player.Name..'\'s team color changed')-- does not print
		--md.AddExperience(player,1)-- you can remove this
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Is this script on the server? If so are you changing the players team on the server as well?

1 Like

Try commenting out the md LevelModuleScript line and seeing if it works.
If so then there’s something inside the Module yielding the whole script.

1 Like

this IsA script in ServerScriptService

i dont know ask Roblox

look

1 Like

I mean the line where you require it.
The module runs code inside of it as soon as it is required. (like a loose while true do loop for example.)

1 Like
  1. works

  2. works

  3. works

  4. works

  5. works

i think i am going to require() the module later

1 Like

You should really check what is yielding the ModuleScript.
Otherwise when you try to utilize it again it will not run any code beyond the require line.

1 Like

From what I can gather from the replies above the issue is to do with the module you are requiring at the top of your script yielding somewhere(e.g: by using wait() or an infinite while loop yielding the code completely). Depending on your code inside the module this could be fixed by either removing the yielding code or by wrapping the yielding code inside a coroutine. Alternatively you could look into Roblox’s task library if you want code to run after a certain period of time instead of yielding the entire script.

However, if you don’t want to modify the code inside the ModuleScript you could change how you are handling PlayerAdded. At the moment you aren’t accounting for cases where the PlayerAdded event is connected after players have already joined the game which could cause some edge cases where the PlayerAdded event is not fired for some players . I think this is the problem you are experiencing, the module is yielding causing the PlayerAdded event to get connected after you’ve joined the game.

The below code shows how you could fix your code by looping through all the players currently in the game and firing an onPlayerAdded functions for those players. Then connecting PlayerAdded as normal.

local Players = game:GetService("Players")

local md = require(game.ReplicatedStorage:WaitForChild("LevelModuleScript"))

local function onPlayerAdded(player)
	player:GetPropertyChangedSignal("Team"):Connect(function()
		-- Do something when the player changes team
	end)
end

-- Loops through all the players in the game and fires the onPlayerAdded function.
-- Handles cases where the PlayerAdded event is connected after players have already
-- entered the game
for _, player in ipairs(Players:GetPlayers()) do
	task.spawn(function()
		onPlayerAdded(player)
	end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

i fixed it
the module script is parented by an script and is not there when it is

d

1 Like