On touch unanchor script, unanchors the whole game

the thing is, i dont think its misplaced, because i started with 1 part and tested it a few time and it worked, and these buildings were made from copy and pasting that part

Denial can lead to the cause. Just see if you can find something, itā€™s likely you just misplaced a specific script.

1 Like

The script isnā€™t the issue from what I tested myself, it has to be the position of the script affecting it

1 Like

i found it! lemme test if it happens again

1 Like

Alright, letā€™s hope that fixed the issue!

1 Like

Glad to know you found it! Let us know if the problem persists

1 Like

It fixed it! tysm guys, ive had this problem for so long and had to seal off this part of the game because i didnt know how to fix it!, can you help me with one more thing? i want the broken apart parts to become uncollideable after a few seconds otherwise itll cause lag. can you help me

you can also do
ā€˜v.CanCollide = falseā€™

1 Like

just at the bottom of the script? and with a wait (20) above it right?

in this part of the script;

		for i, v in pairs(script.Parent.Parent:GetChildren()) do
			if not v:IsA("BasePart") then continue end
			v.Anchored = false
			local smoke = Instance.new("Smoke")
			smoke.Parent = v
			smoke.Color = Color3.new(197, 196, 199)
			smoke.Opacity = 0.25
			smoke.RiseVelocity = 6
		end

ā€˜v.CanCollide = falseā€™ inside the for loop.

1 Like

The issue with what @Wyzloc stated is that a method like that may cause some parts to fall out of the world since they are uncollideable, meaning they can fall through the world. If you want to make it so once something is destructed, donā€™t have any collisions with certain things, you could try learning about CollisionGroups. But generally the main thing is that a lot of physics will lag the game, although there definitely are some ways to optimize it

1 Like

thats why i want to make it fall through the world, itll be, you destroy it, some effects playout, after while the parts will fall away. i have an automatic every 5 min regen script that regens certain parts every 5 minutes including this building.

Ohhh, I see. Sorry that I misunderstood the question. Then yea, I think their method should work for you

1 Like

i added it to the script but now not the whole model gets unanchored and some parts only cancollide off and the smoke doesnt stop emitting, script:

local ready = true
local sound = script.Parent.Soundā€“Change to your sound location.
local delaytime = 5
script.Parent.Touched:Connect(function()
if ready == true then
ready = false
for _, v in pairs(script.Parent.Parent:GetChildren()) do
v.Anchored = false
local smoke = Instance.new(ā€œSmokeā€)
smoke.Parent = v
smoke.Color = Color3.new(197, 196, 199)
smoke.Opacity = 0.25
smoke.RiseVelocity = 6
wait (15)
v.CanCollide = false
end
sound:Stop()
sound:Play()

	wait(delaytime) -- Amount of till making smoke dissapear

	for i, v in pairs(script.Parent.Parent:GetChildren()) do
		if v:IsA("BasePart") then
			v.Smoke:Destroy()
		end
	end
	script:Destroy()
	ready = true
end

end)

why donā€™t you clone the objects then, and have it respawn after being destroyed. like this for example:

local building = workspace.BuildingName
local Duration = 30 -- 30 seconds till buildings back
for _,v in pairs(building:GetChildren()) do
	if v:IsA("BasePart") then
		v:SetAttribute("OldTransparency", v.Transparency)
		v.Transparency = 1 -- making sure nobody can see the real one
		local part = v:Clone()
		part.CanCollide = false
		part.Anchored = false
       part.CFrame = v.CFrame
       part.Parent = v.Parent
       game.Debris:AddItem(part, 30)
	end
end
wait(Duration)
for _,v in pairs(building:GetChildren()) do
	if v:IsA("BasePart") then
		local OldTransparency = v:GetAttribute("OldTransparency")
		if OldTransparency then
			v.Transparency = OldTransparency
		end
	end
end
1 Like

thank you but i like my current regen system, i just have the problem listen above ur msg

I wasnā€™t trying to replace your script I was just giving an example of how it would be done through another personā€™s perspective.

Anyways itā€™s pretty hard to figure out what the problem is when you donā€™t show any gifs, or examples of what youā€™re experiencing.

1 Like

Your issue is that it sets the properties of one part and then yields 15 seconds before going to the next, try this

local ready = true
local sound = script.Parent.Sound--Change to your sound location.
local delaytime = 5
script.Parent.Touched:Connect(function()
	if ready == true then
		ready = false
		for i, v in pairs(script.Parent.Parent:GetChildren()) do
			if not v:IsA("BasePart") then continue end
			coroutine.wrap(function()
				v.Anchored = false
				local smoke = Instance.new("Smoke")
				smoke.Parent = v
				smoke.Color = Color3.new(197, 196, 199)
				smoke.Opacity = 0.25
				smoke.RiseVelocity = 6
				wait(15)
				v.CanCollide = false
			end)()
		end
		sound:Stop()
		sound:Play()
		
		wait(delaytime) -- Amount of till making smoke dissapear
		
		for i, v in pairs(script.Parent.Parent:GetChildren()) do
			if v:IsA("BasePart") then
				v.Smoke:Destroy()
			end
		end
		script:Destroy()
		ready = true
	end
end)

This will wrap each in their own thread so the wait doesnā€™t affect the loop

1 Like

i did this and it unanchored everything again and stopped the smoke but didnt uncollideable the parts after 15 seconds, edit: what i mean with unanchored everything again is that it unanchored everything thats needed to be unanchored so not the whole map, just to clarify lol

Hmm, try changing the Coroutine.wrap code to

coroutine.wrap(function()
	local part = v
	part.Anchored = false
	local smoke = Instance.new("Smoke")
	smoke.Parent = v
	smoke.Color = Color3.new(197, 196, 199)
	smoke.Opacity = 0.25
	smoke.RiseVelocity = 6
	wait(15)
	print("UnColliding Part")
	part.CanCollide = false
end)()

Edit: It could also be that the script is being destroyed before the 15 seconds are up, try increasing the delay

1 Like