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

How to unanchor a model from a script AFTER a specific time?

Hi, i have been looking for hours how to do it but couldn't find anything. Does anyone know how to unanchor a model from a script AFTER a specific time? Lets say if map (Model) named (Map1) spawns in, then after 5 seconds the whole map will unanchor.

Map changing script

while true do
	game.Lighting.Map1:clone().Parent = game.Workspace
	wait(10) --Change this to the time between each map. Goes in seconds not minutes or hours. You can do min. or hrs. if u know how much seconds are on there.
	local msg = Instance.new("Message")
	msg.Parent = game.Workspace
	msg.Text = ("Loading next map")--Change this to the title of the map.
	wait(4)
	msg:remove()
	game.Workspace.Map1:remove()
	wait(2)

	game.Lighting.Map2:clone().Parent = game.Workspace
	wait(10)--Change this to the time between each map.
	msg.Parent = game.Workspace
	msg.Text = ("Loading next map")--Change this to the title of the map.
	wait(4)
	msg:remove()
	game.Workspace.Map2:remove()
	wait(2)

	game.Lighting.Map3:clone().Parent = game.Workspace
	wait(10)--Change this to the time between each map.
	msg.Parent = game.Workspace
	msg.Text = ("Loading next map")--Change this to the title of the map.
	wait(4)
	msg:remove()
	game.Workspace.Map3:remove()
	wait(2)

end 

2 answers

✓ Accepted answer

You can use GetDescendants() instead of GetChildren(). The difference is that GetDescendants() gets ALL of the contents (including other models inside the model) while GetChildren() only gets the model's contents you assigned to (only gets children to one model).

wait(5)
local Descendants = MapModel:GetDescendants()

for i = 1, #Descendants do 
	local child = Descendants[i]
	if child:IsA("BasePart") then 
		child.Anchored = false 
	end
emd

2 comments

0

Could you please show me how should i use it in my script i mentioned?

0

Got it worked, thanks. But the problem continues. How do i make it that if it map gets unanchored then it wont start breaking/falling by itself. I want that only players and disasters can break map blocks.

Well you could use a for loop (as far as i know)

Like this (assuming Map1 is already in workspace):

wait(5)
for i,v in pairs (workspace.Map1:GetChildren()) do
	if v:IsA("BasePart") then  -- to exclude decals and whatnot
	v.Anchored = false
	end
end

2 comments

0

indent line 4 por favot

0

I sent you a Private message on roblox.

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