script.Parent.Touched:connect(function(other)
if other and game.Players:GetPlayerFromCharacter(other.Parent) then
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
local Character = Player.Character
if Player ~= nil then -- "player" does not exist.
if Player.TeamColor == game.Teams["Medical Department"].TeamColor then
if Character:FindFirstChild("MDPants") then
else
end
if Character:FindFirstChild("Pants") then
Character.Pants:Destroy()
else
local Pants = Instance.new("Pants")
Pants.Name = "MDPants"
Pants.PantsTemplate = "http://www.roblox.com/asset/?id=1011421418"
Pants.Parent = Character
end
if Character:findFirstChild("MDShirt") then
else
if Character:findFirstChild("Shirt") then
Character.Shirt:Destroy()
else
local Shirt = Instance.new("Shirt")
Shirt.Name = "MDShirt"
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=1011380619"
Shirt.Parent = Character
end end
elseif not Player.TeamColor == game.Teams["Medical Department"].TeamColor then
end
end
end
end)
✓ ANSWER ACCEPTED
Anyone know why this keeps giving the player the pants over and over?
1 answer
✓ Accepted answer
Hello, tictac67!
I found a little error on your script, here's the solved version:
script.Parent.Touched:connect(function(other)
if other and game.Players:GetPlayerFromCharacter(other.Parent) then
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
local Character = Player.Character
if Player ~= nil then -- "player" does not exist.
if Player.TeamColor == game.Teams["Medical Department"].TeamColor then
if Character:FindFirstChild("MDPants") then --This starts the search for "MDPants"
else
if Character:FindFirstChild("Pants") then
Character.Pants:Destroy()
else
local Pants = Instance.new("Pants")
Pants.Name = "MDPants"
Pants.PantsTemplate = "http://www.roblox.com/asset/?id=1011421418"
Pants.Parent = Character
end
end --This ends the search for "MDPants"
if Character:findFirstChild("MDShirt") then
else
if Character:findFirstChild("Shirt") then
Character.Shirt:Destroy()
else
local Shirt = Instance.new("Shirt")
Shirt.Name = "MDShirt"
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=1011380619"
Shirt.Parent = Character
end end
elseif not Player.TeamColor == game.Teams["Medical Department"].TeamColor then
end
end
end
end)
Hope this works!
Good Luck with your games
2 comments
0
Thank you
0
You can use "not" before a statement to test if it is false
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
probably cause they're still standing on the pad.
@iRoklas no, line 7 and line 10 are there to don't let this...