Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to destroy a part with localscript?

How do i destroy a part with this system?:

for i,v in pairs(Wood.Parent.Script:GetChildren()) do
				    if v:IsA('Part') then
				    	v.Anchored = false
				    end
			    end

I have tried changing v.Anchored = false to v.Destroy

4 comments

0

v:Destroy()

0

although it will only destroy it locally, not on the server, you would need remotes for that

0

Thanks!

0

How do i do that?

1 answer

Its simple, use remote events

For first, create a RemoveEvent on ReplicatedStorage, now create a ServerScript(Script) in ServerScriptService and put this code:

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- Event location

event.OnServerEvent:Connect(function(player,location,arg) -- you need to put the player.
	if arg == "DestroyChildrenOf" then
		for i,v in pairs(location:GetChildren()) do
			if v:IsA("Part") then
				v:Destroy() -- Changed to :Destroy
			end
		end
	end
end)

Now on LocalScript send the location:

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- Event location

event:FireServer(Wood.Parent.Script,"DestroyChildrenOf") -- Now fired server and started, (i send the location of objects to server destroy.)

Hope it helped :D

Errors? tell-me on comments.

Wiki pages:

Remote Events/Functions

Destroy

Solved your problems? put [SOLVED] in title or accept a answer.

9 comments

0

Hey, the problem i have for a long time is that i need to be able to copy it.

0

When you hover mouse, will show a button as "View Source", click in this button and copy and paste in your roblox studio

0

Hey, I would have to change the name of every remote event, that isnt possible in my case

0

you can change the name in script.

0

That i would have to do that for almost 500 of them, It would be a lot better if i could just copy the normal script over and over

0

why would you need 500 scripts? Either way a bad practice, I'd rethink how you do things if I were you

0

Okay, so i need to create a script for when i click a "tree" with a tool it needs to make the parts of it unanchord. I had it working with a Clickdetector but it would not work when holding a tool. Do you have any ideas?

0

The problem with this solution is that exploiters will be able to delete any part in the game.

0

Which is why you implement server checks, you can have a list of parts that are destroy-able

This discussion is preserved as it was. New answers, comments, and votes are closed.