You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
A decay script that decays bricks.
- What is the issue? Include screenshots / videos if possible!
It seems to stop working when it gets to the first task.wait() command.
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
None, yes, genuinely surprised by how this doesn’t work
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
if script.Parent.Name=="Brick" then --check
if script.Parent.Anchored==false then --check 2
print("check 1")
task.wait(10)
print("check 2")
script.Parent.Material=Enum.Material.CorrodedMetal
print("check 3")
task.wait(2)
print("I am no more... :(")
script.Parent:Destroy()
script:Destroy()
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
The most likely cause is that something is destroying the script (either directly, or through deleting the part) while the script is waiting.
Are you 100% sure that the part didn’t get deleted through falling through the map, and that nothing else would have deleted it?
No. The parts are only unanchored when a certain event is triggered, hence why theres the second check.
Have the parts got CanCollide on? If not, they’re falling through the map and being destroyed
They have CanCollide on, yes. charcharchar
Have you tried wait instead of task.wait?
This did not work, I tried it just now, but it resulted in failure.
Does the first check print in console just fine and then the whole thing stops functioning?
Yes. It just breaks down after the first task.wait() in the script, anything above the line works.
EDIT: Im going to sleep, see you tomorrow!
I tried to replicate the scenario by setting up a Part, naming it Brick and unanchoring it, and played around with that setup for a while before concluding that, as a standalone script, it works just fine for me - the brick will pass check 1, wait for 10 seconds, pass check 2, switch to the CorrodedMetal material, pass check 3 and disappear another few seconds later.
Only when I deleted the script or the entire brick from the server’s POV did it stop in the middle of task.wait(), and didn’t pass any errors. So my theory is that there is something external affecting your corrosion script, you may just not be aware of it.
If you put this in ServerScriptService and then try running the event again, does it possibly hint at anything?
local brick = game.Workspace:FindFirstChild("Brick") -- change this to wherever your brick is located
local script = brick:FindFirstChild("Script")
brick.Destroying:Connect(function()
print("brick was destroyed")
end)
script.Destroying:Connect(function()
print("corrosion script was destroyed")
end)
It works differently, basically, Decay is inside ServerStorage, and it gets put into the brick whenever the Builder creates the brick, through a script in ServerScriptService named “Setup”.
Then, it checks for the conditions like the Name and Anchored property, if it is named “Brick” and is unanchored, it will do the deed.
Also it is not just one brick; It is a multitude of bricks that are placed by Builders every 2.5-7.5 seconds.