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: Clear script

Previous Thread :: Next Thread 
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
06 Oct 2012 10:46 PM
player = script.Parent.Parent.Parent.Parent.parent

function chat(msg)
if msg == "clear" then
c = player.StarterGear.GetChildren()
c:Destroy()
local M = Instance.new("Message")
M.Parent = player.Character.Torso
M.Text = "Tools cleared!"

else

local b = Instance.new("Message")
b.Text = "An error has occured"
end
end

game.Player.PlayerAdded:connect(chat)



this script is very simple alls it does is for my gear gui testing game when you say "clear" it clears all your gears from your backpack and starterGear but it isn't working, please help.
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
06 Oct 2012 10:47 PM
This script looks like it goes in the Player, so PlayerAdded won't fire because the Player already Spawned.

Plus You forgot to Capitalise P in the last Parent
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 10:48 PM
    player = script.Parent.Parent.Parent.Parent.Parent --Last Parent should be capitilized
    function chat(msg)
    if msg == "clear" then
    player.BackPack:ClearAllChildren()
    player.StarterGear:ClearAllChildren() --These methods are easier for what you're doing
    local M = Instance.new("Message")
    M.Parent = player.Character.Torso
    M.Text = "Tools cleared!"
    else
    local b = Instance.new("Message")
    b.Text = "An error has occured"
    end
    end
    game.Player.PlayerAdded:connect(chat)

¤ ¤ † K M X D † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 10:50 PM
Eh, after a second look...

    function Added(player)
    player.Chatted:connect(function(msg)
    if msg == "clear" then
    player.BackPack:ClearAllChildren()
    player.StarterGear:ClearAllChildren() --These methods are easier for what you're doing
    local M = Instance.new("Message")
    M.Parent = player.Character.Torso
    M.Text = "Tools cleared!"
    else
    local b = Instance.new("Message")
    b.Text = "An error has occured"
    end
    end)
    end
    game.Players.PlayerAdded:connect(Added)

¤ ¤ † K M X D † ¤ ¤
Report Abuse
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
06 Oct 2012 10:50 PM
ClearAllChildren() uses :Remove
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 10:54 PM
. . .

    Game.Players.PlayerAdded:connect(function(Player)
      Player.Chatted:connect(function(Chat)
        if Chat == "clear" then
         Player.BackPack:ClearAllChildren()
         Player.StarterGear:ClearAllChildren()
         local Message = Instance.new("Message", Player.PlayerGui)
         Message.Text = "Tools cleared!"
         wait(3)
         Message:Destroy()
        else
         local Message = Instance.new("Message", Player.PlayerGui)
         Message.Text = "An error has occurred"
         wait(3)
         Message:Destroy()
        end
      end)
    end)

@Chop

I think it'd still be better than to use loops.

¤ ¤ † K M X D † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 10:55 PM
BackPack should also be Backpack.

¤ ¤ † K M X D † ¤ ¤
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
06 Oct 2012 11:07 PM
Thanks for trying to help but it did not help, I put the script in the StarterGui
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 11:11 PM
Put it in Workspace. Remember to change "BackPack" to "Backpack".

¤ ¤ † K M X D † ¤ ¤
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
06 Oct 2012 11:14 PM
Thanks! Worked perfectly fine. Can you help me understand the changes you made though so I can learn from my mistake?
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Oct 2012 11:19 PM
    player = script.Parent.Parent.Parent.Parent.parent --Not needed if use use the PlayerAdded event and it's argument
    function chat(msg) --This function is connected to the PlayerAdded event, instead of the Player's Chatted event
    if msg == "clear" then
    c = player.StarterGear.GetChildren() --You can't simply do that, as it would return a table, and it should be :GetChildren()
    c:Destroy()
    local M = Instance.new("Message")
    M.Parent = player.Character.Torso --Not sure if it would make the message local, so I used PlayerGui
    M.Text = "Tools cleared!"
    else
    local b = Instance.new("Message") --Didn't parent the message
    b.Text = "An error has occured" --Both wouldn't remove the messages
    end
    end
    game.Player.PlayerAdded:connect(chat)

¤ ¤ † K M X D † ¤ ¤
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