Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-3

A Script That Removes An Object?

Asked by 9 years ago

I've been editing and messing with a slime game recently. This is the script that creates the "IsSlime" object. I would like to make a gui, that when clicked asks if they would like to reset (remove) their current slime. I have no idea where to start.

(Create script.)

while true do wait(1) if script.Parent.Debounce.Value == true then local Name = script.Parent.Turner.Value local W = game.Workspace:GetChildren() local HasSlime = false for i = 1, #W do if W[i]:findFirstChild("IsSlime") ~= nil then if W[i].Owner.Value == Name then HasSlime = true end end end if HasSlime == false then script.Parent.Motor.BottomSurfaceInput = "Constant" wait(0.5) local Slime = game.Lighting["No-name"]:clone() Slime.Owner.Value = Name Slime.Head.CFrame = CFrame.new(script.Parent.Parent.Faucet.Spout.Position) * CFrame.new(0, -1, 0) Slime.Head.Velocity = Vector3.new(0, 0, 0) Slime.Parent = game.Workspace Slime.Head.BrickColor = BrickColor.Random() Slime.Humanoid.MaxHealth = 10 Slime.Humanoid.Health = 10 local materials = {"Plastic", "Brick", "Cobblestone", "Concrete", "CorrodedMetal", "DiamondPlate", "Fabric", "Foil", "Granite", "Grass", "Ice", "Marble", "Metal", "Pebble", "Sand", "Slate", "SmoothPlastic", "Wood", "WoodPlanks"} local matpick = math.random(1, 19) Slime.Head.Material = materials[matpick]
local Chance = math.random(1, 20) if Chance == 20 then Slime.Head.Reflectance = 0.4 Slime.Material = "Plastic" end if game.Players:findFirstChild(script.Parent.Turner.Value) ~= nil then if game.Players:findFirstChild(script.Parent.Turner.Value):IsInGroup(467010) == true then local M = Instance.new("Model") M.Name = "VIP" M.Parent = Slime end end game.Lighting.PlantTip:clone().Parent = game.Players:findFirstChild(script.Parent.Turner.Value).PlayerGui wait(1) script.Parent.Motor.BottomSurfaceInput = "NoInput" end script.Parent.Debounce.Value = false end end

1 answer

Log in to vote
3
Answered by 9 years ago

To remove an object, you can use the method remove

Part:remove()
--This is the same as
Part.Parent = nil

Both of the examples above SHOULD NOT BE USED. They are deprecated. Remove has been replaced with Destroy.


Remove changes the part's parent to nil, meaning that you can always retrieve it.

Part:remove()
Part.Anchored = false --Even after the object is removed you can still edit it
Part.Parent = workspace

When you use remove you make little "zombies"(read this article.) because the objects are still there you just cannot SEE them. When you use Destroy however, it will PERMANENTLY delete them.

Part:Destroy()

Now, TheAlphaStigma asked a clever question, He used the following script:

local p = Instance.new("Part", workspace)
p:Destroy()
print(p) --This should of made an error

Well, that doesn't mean that destroy doesn't work, it does completely delete it. Look, unlike the remove method, If you do the following:

Part:Destroy()
Part.Anchored = false
Part.Parent = workspace --Error Error Error; Part Does not exist.

There are other ways to delete items, the AddItem is a way to delete stuff, you must be asking, "How is that possible?" AddItem adds the part into Debris, Debris basically means trash and etc. AddItem is part of the Debris Service.

local debris = game:GetService("Debris") --This is how you reach the debris service.
debris:AddItem(Part, 3) --What to delete, how long we wait before we delete it.

ClearAllChildren is dangerous if you use it on workspace. It can make your game get REKT. It deletes all the characters and everything. ClearAllChildren deletes everything INSIDE of an object, not the model itself.

Model:ClearAllChildren() --If there is a part inside of the model, the part will get deleted. The model will not.


Hope it helps!

0
@TheAlphaStigma , lol you deleted your comment, you didn't read that one part. Also, what was that question about the delete doesn't work thing. EzraNehemiah_TF2 3552 — 9y
0
I know. :P I noticed that right after I posted my comment, so I removed it because it was Off-Topic from your answer. Also, I don't remember anything about me mentioning Deleting (from my last comment, that is). o_e TheeDeathCaster 2368 — 9y
0
Nit: Part:Remove() isn't the same thing as Part.Parent = nil -- it also :Remove()s all of its children BlueTaslem 18071 — 9y
0
I thought that would of been obvious :\ EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question