GetPropertyChangedSignal runs twice

  1. What do you want to achieve? Keep it simple and clear!
    When the player respawns, I want “A” to print once.

  2. What is the issue? Include screenshots / videos if possible!
    The first time I join the game, it works perfectly and runs once, however when I respawn, and change teams, GetPropertyChangedSignal runs twice, which prints “A” twice.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t been able to find anyone on the forum with this issue, I also tried switching to “Changed”, which doesn’t seem work.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(chr)
		plr:GetPropertyChangedSignal("Team"):Connect(function()
			if plr.Team == game.Teams.Playing then
				print("A") -- This prints twice for some reason
			end
		end)
	end)
end)

You can try using :Wait() instead of :Connect() like so:

plr.CharacterAppearanceLoaded:Wait() -- yields until it is fired

if plr.Team == game.Teams.Playing then
	print("A") -- This prints twice for some reason
end

if that helps.

But wouldnt this pause the whole script? Or only that segment (dont think so)

But how would that be different though? The team doesn’t get changed as you respawn, plus, it’s not characterappearanceloaded that’s running twice, it’s the getpropertychangedsignal.

I see, well this is just an idea but you can probably store the Players connection to a Array, and check if the Connection Exists when the second fires, so it doesnt fire twice like so:

local PlayerEvents = {} -- to Store Player Connections

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(chr)
        if not PlayerEvents[plr.UserId] then -- Checks if a index does not exist for the Player
		    if plr.Team == game.Teams.Playing then
                PlayerEvents[plr.UserId] = Data -- Adds Data to Table
		    end
        end
	end)
    plr.CharacterRemoving:Connect(function() -- IF needed
        PlayerEvents[plr.UserId]:Disconnect() -- Disconnects Event (it may do this automatically, i dont remember)
        PlayerEvents[plr.UserId] = nil -- removes the Data so it can be reused
    end)
end)

It seems that this has the exact same problem as before.

I figured out what was wrong. Apparently when you switch teams after respawning, it thinks the team you are on is also being switched, along with switching to “Playing” team if that makes any sense, so I added an additional check.

Here’s my final script if anyone had trouble with this in the future:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(chr)
		local lastteam = plr.Team
		plr:GetPropertyChangedSignal("Team"):Connect(function()
			if plr.Team == game.Teams.Playing and plr.Team ~= lastteam then
				lastteam = plr.Team
				print("A")
			end
		end)
	end)
end)
1 Like