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 » Scripters
Home Search
 

Re: How do I keep Instance.new from being spammed?

Previous Thread :: Next Thread 
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
03 Mar 2015 03:10 PM
Okay, so I made a gui and when someone clicks it, it will insert a Special Mesh into all the LocalPlayer's parts, but I'm trying to figure out how to make it such that if the "NewMesh" already exists in the player the button won't insert another mesh. Help?

button = script.Parent

button.MouseButton1Click:connect(function(clicker)
local bodyParts = game.Players.LocalPlayer.Character:GetChildren()
for i,b in pairs (bodyParts) do
if (b.className == "Part") then
local newMesh = Instance.new("SpecialMesh", b)
newMesh.Name = "NewMesh"
b.BrickColor = BrickColor.new("Black")
elseif (b.className == "Hat") then
b:remove()
elseif (b.className == "Shirt") then
b:remove()
elseif (b.className == "Pants") then
b:remove()
elseif (b.className == "ShirtGraphic") then
b.Graphic = ""

end
end
end)

function GetRidofOldMesh()
local OldMesh = game.Players.LocalPlayer.Character.Head:FindFirstChild("NewMesh")
local bodyParts = game.Players.LocalPlayer.Character:GetChildren()
for i,b in pairs (bodyParts) do
if OldMesh ~= nil then
OldMesh:remove()
print("Deleted mesh")
end
end
end

button.MouseButton1Click:connect(GetRidofOldMesh)
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
03 Mar 2015 03:12 PM
you add a debounce and remove old ones

also stop using destroy
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
03 Mar 2015 03:12 PM
*stop using remove()

use destroy()
Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
03 Mar 2015 03:22 PM
How would I know which mesh to delete since the meshes have the same names? Ex. If two meshes are inserted into the character both named "NewMesh" how will the script know which mesh to delete?
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
03 Mar 2015 03:23 PM
change the name of the mesh when created to be named "Mesh_PlayerNameHere"
Report Abuse
AnimeWiki is not online. AnimeWiki
Joined: 26 Oct 2014
Total Posts: 460
03 Mar 2015 03:25 PM
a = {}


function createmesh(part)
local mesh = Instance.new("SpecialMesh", part)
table.insert(a,mesh)
return mesh
end


for k,v in pairs(a) do k,v = nil,nil end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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