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.
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.
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)