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

How to break on big block into smaller blocks? (Still no answer)

I have a game idea that would be fun(for me at least) and creating the map would be very hard. So i was thinking what if you can have a building made of 5 parts but can be broken into 1000 parts. Not sure if this would be possible but the code might look like this:

wall = game.Workspace.Wall4
player = game.Players.LocalPlayer -- Not sure if this is right

wall.Touched:connect(function(part) -- If I touch the wall I want it to break
	if part.Parent = player then -- Make sure a player touched it
		-- Code for splitting wall would be here
		wall:GetChildren().Anchored = false --Now the wall would be a model with its broken pieces in it and the pieces would fall
	end
end)

I'm still kind of new to lua so if I made any mistakes in my code up there then tell me plez :D

3 comments

0

You should be using LocalPlayer.Character, as LocalPlayer holds mostly GUI and unequiped tools in your backpack, aswell as some scripts. However, LocalPlayer.Character is the avatar, and has all parts of the player as well as scripts for animating and movement.

0

Also, you could just have a model with a bunch of parts in it and run the function for if one of them is touched. I believe that there is a glass breaking tutorial on youtube, which you could watch.

0

This really does not answer my question because I want one piece to break into many not have many pieces just nonanchor

1 answer

The code below is just an example from what you have shown. Use your creativity to come up with ideas on how you could have the part break and ask questions if you have trouble along the way.

This code is technically just a way to rewrite what you currently have to make it work better, or work at all. You can mess around with BodyVelocity to make the broken parts fly in different directions and so on.

(My hierarchy for this has parts inside of Wall4 that represent when it breaks, and the script in ServerScriptService)

local Players = game:GetService("Players") --Loading and reliability purposes if we were to use Players
local wall = workspace.Wall4
--You would most likely want this in a server script, so you cannot use LocalPlayer (only used in local scripts)

wall.Touched:connect(function(hit)--This gets what part hit the wall
    if hit.Parent:FindFirstChild("Humanoid") then --This checks if the thing that hit it has a humanoid
        for i,v in pairs(wall:GetChildren()) do --v is the child you are currently looking at basically
			if v:IsA("Part") then --So that this doesn't count the TouchTransmitters
				v.Anchored = false --If you just want to make them unanchored you want want a loop
				v.Parent = game.Workspace--So that we can remove wall if we wanted
				v.Transparency = 0--I had them transparent so they couldnt be seen
				v.CanCollide = true--So people can now touch them, I had this off
			end
		end
		wall:Destroy()--If you want it to be permanently broken, idk why you would still need this
    end
end)

Please remember to accept my answer if it has helped you successfully solve your issue. Feel free to comment on my answer or message me if you have any concerns, I have done anything wrong, or I have not solved your question. Thanks!

2 comments

0

you can also use a for loop and clone the brick, make it smaller, set anchored to false and use velcocity to spread them apart.

0

Yes. As I said in bold text, I just made this based on what they had to make it look more like what they had already written.

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