generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Why is this happening?!?!??!?

Previous Thread :: Next Thread 
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
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
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
09 Feb 2014 06:18 PM
print("v.ClassName")
It needs to have the perinthists.
Report Abuse
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
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 is online. 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 is not online. 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 is not online. 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
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
09 Feb 2014 06:58 PM
Nope. Just trying to help.
Report Abuse
Vyxium is not online. 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
Solsticedev is not online. Solsticedev
Joined: 02 Feb 2014
Total Posts: 343
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
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image