-Hello everyone, I am having some trouble using Seat.Changed:Connect
(Seat being the script parent)
-
What do I want to achieve?
-I want to make a chair that, when seated the player gets his team changed to another one. However, the script wont change the team, if there is already one player in it.
(But only the event connected to the function is causing me trouble) -
What is the issue?
-When I use the event Seat.Changed:Connect to connect the function that I will show down later, this happens.
-
What solutions have you tried so far?
-I have found out that using an event that activates the function when the seat is touched everything works well, however it appears to only fire when the player leaves the chair.
(Other methods like using click detectors worked without a problem.)
Not understanding why the event may cause a error regarding the team color, I would like to know if im using a bad Event or just bad coding from my part.
local teamManager = BrickColor.new("Shamrock");
local seat = script.Parent; --The parent is a normal seat
seat.Changed:Connect(function(TeamCheck)
--seat.Touched:connect Works, but only once you leave the chair
local plr = game.Players:GetPlayerFromCharacter(TeamCheck.Parent);
local numberPlayers = 0
for _,myplayer in pairs(game.Players:GetChildren()) do
if myplayer.TeamColor.Name == "Shamrock" then
numberPlayers = numberPlayers + 1
end
end
if numberPlayers == 0 then
plr.TeamColor = teamManager
end
end)
If someone understand why this is happening I would be very grateful, thank you for you time and help!