So, the script provided below is about a remote event being fired into a server script (not sure if I used the right words but you get the idea) and so that once the remote event is fired, this script will run. The output doesn't show any errors but it's still not working.
So in the script, after checking if the player is inside the "France" team, then the script should kill the player so they can reset and be given proper uniform for their class (officer). And then after that, I used the CharacterAdded event to detect when they re spawn and give them their proper uniform. But it won't work. I think this is where the issue is, but I can't find it.
-- SERVICES local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = game:GetService("Players") local Team = game:GetService("Teams") --EVENTS local OfficerEvent = ReplicatedStorage:WaitForChild("OfficerEvent") local InfantryEvent = ReplicatedStorage:WaitForChild("InfantryEvent") local RiflesEvent = ReplicatedStorage:WaitForChild("RiflesEvent") -- OFFICER EVENT OfficerEvent.OnServerEvent:Connect(function(player) local character = player.Character if player.Team == game.Teams.France then player.Character.Humanoid.Health = 0 player.CharacterAdded:Connect(function() character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://1422626514" character:WaitForChild("Pants").PantsTemplate = "rbxassetid://1070344465" end) end end)
Thanks in advance!
That's a common mistake there. You defined a player's team as an actual team, and that won't work.
if player.Team == game.Teams.France then
won't work, because while this may seem logical, it is not to the game.
Here is a proper way to define this:
if player.TeamColor == game.Teams.France.TeamColor then
Aditionally, often times you may encounter that people are not wearing clothing, such as pants or a shirt at all, here is how we can prevent bugs about it and solve it:
function changeShirt(character,shirtTemplateId) -- This function takes 2 parameters, the Character of the player and the ShirtTemplate ("rbxassetid://XXXXXX") local hasShirt = false local shirt = nil for i,v in pairs(character:GetChildren()) do if v:IsA("Shirt") then hasShirt = true shirt = v -- If there is a shirt existing, then we will define the valuable "shirt" as it, so we can use it later. end end if hasShirt == false then -- It is important to mention that this will run AFTER the loop, so no worries! shirt = Instance.new("Shirt",character) shirt.ShirtTemplate = shirtTemplateId else shirt.ShirtTemplate = shirtTemplateId end end function changePants(character,pantsTemplateId) -- This function takes 2 parameters, the Character of the player and the PantsTemplate ("rbxassetid://XXXXXX") local hasPants = false local pants = nil for i,v in pairs(character:GetChildren()) do if v:IsA("Pants") then hasPants = true pants = v -- If the person has pants, we save 'em into the pants variable. end end if hasPants == false then -- Again, this runs after the loop is done. pants = Instance.new("Pants",character) pants.PantsTemplate = pantsTemplateId else pants.Pants = pantsTemplateId end end
We call it using:
player.CharacterAdded:Connect(function(character) changeShirt(character,"rbxassetid://1422626514") changePants(character,"rbxassetid://1070344465") end)