|
| 09 Feb 2014 06:13 PM |
So I want the hats to be removed from a player when they join the game:
function removeHats(plr) for i, v in pairs(plr:GetChildren()) do if v.ClassName == "Hat" then v:Remove() end print(v.ClassName) end print(plr) end
Workspace.ChildAdded:connect(removeHats)
I made it print v.ClassName, and it never prints "Hat"? It prints all of the character's parts, such as humanoid and part, but it never prints the class name of the hat, as if it is skipping over it. I am completely stumped. Anyone know what is wrong? |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2014 06:18 PM |
print("v.ClassName") It needs to have the perinthists. |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2014 06:21 PM |
function removeHats(plr) for i, v in pairs(plr:GetChildren()) do if v:IsA("Hat") then v:Remove() end print(v) end print(plr) end
Workspace.ChildAdded:connect(removeHats)
v.ClassName doesnt work, you do v:IsA("Hat") instead. |
|
|
| Report Abuse |
|
|
WebGL3D
|
  |
| Joined: 04 Sep 2013 |
| Total Posts: 28311 |
|
|
| 09 Feb 2014 06:48 PM |
function removeHats(plr) for i, v in pairs(plr:GetChildren()) do if v.ClassName == "Hat" then v:Remove() end print(v.ClassName) end print(plr) end
Workspace.ChildAdded:connect(removeHats)
Don't know why your script isn't working, but I'd go about this task like this,
function newPlayer(Player) local function char(c) for n,o in pairs(c:GetChildren())do if(o:IsA("Hat"))then o:Destroy() end end end Player.CharacterAdded:connect(char) if(Player.Character)then char(Player.Character)end end game.Players.PlayerAdded:connect(newPlayer) for n,o in pairs(game.Players:GetPlayers())do newPlayer(o)end -- This line is for offline mode, which sometimes doesn't fire the PlayerAdded event
~ 1Topcop ~ Java3D ~ WebGL3D ~ Hoard3D ~ Thug3D |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 09 Feb 2014 06:51 PM |
FIrst of all, I wouldn't check EVERY model that joins the Workspace. Why not check only the players once they spawn?
game.Players.PlayerAdded:connect(function(newPlayer) newPlayer.CharacterAdded:connect(function(char)
char.ChildAdded:connect(function(possibleHat) if possibleHat:IsA("Hat") then possibleHat:remove() end end) for _,v in pairs(char:GetChildren()) do if v:IsA("Hat") then v:remove() end end
end) end) |
|
|
| Report Abuse |
|
|
Vyxium
|
  |
| Joined: 31 Aug 2010 |
| Total Posts: 1020 |
|
|
| 09 Feb 2014 06:57 PM |
| usfirepilot, you have no idea what you're talking about. |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2014 06:58 PM |
| Nope. Just trying to help. |
|
|
| Report Abuse |
|
|
Vyxium
|
  |
| Joined: 31 Aug 2010 |
| Total Posts: 1020 |
|
|
| 09 Feb 2014 07:03 PM |
| well you have no idea what you are saying because you're giving out false information |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2014 07:06 PM |
A script I use to remove hats, including afater players respawn, is
while wait() do for i,v in pairs(workspace:GetChildren()) do for i,c in pairs(v:GetChildren()) do if c amd c:IsA("Hat") the c:destroy() end end end end |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2014 07:08 PM |
| I fixed it, it wasn't working because it was checking for the hat when it hadn't been loaded yet. All I did was add a wait(3).. Thanks anyways, guys. |
|
|
| Report Abuse |
|
|