I am planning on making a spleef game where you can get abilities and stuff.
However the script is quite delayed. The fist step (as in whenever the parts first crack) are not delayed whatsoever. But the second step (as in whenever the parts disappear) is delayed by quite a bit
I assume that the reason for this is because of the “if” statement however i do not see how i could make other things destroy the parts without it.
I Need a way to use a if statement or something similar to it without it delaying my script
Replace the code inside the if Humanoid then block with this:
task.wait(.13)
v:SetAttribute("BrickCrack", v:GetAttribute("BrickCrack") + 1)
v.Material = "Pebble"
v.BrickColor = BrickColor.Black()
v.Transparency = .5
if v:GetAttribute("BrickCrack") > 2 then
v.Transparency = 1
v.CanCollide = false
end
It seems the delay is probably caused by your variable GetBreaks. The problem is that by calling :GetAttribute(“BrickCrack”), you aren’t getting the attribute itself as it updates in real time, you’re getting the attribute’s current value at the time that the line of code ran.
This is relevant because you wait 0.13 seconds before checking GetBreaks in a conditional statement, meaning that in the line if GetBreaks>2 then, you aren’t checking BrickCrack’s new value after adding 1 to it, but instead checking BrickCrack’s value as it was 0.13 seconds ago.
And since BrickCrack needs a value of 3 for the brick to break, as well as BrickCrack pretty much having a 0.13 second cooldown before it can be increased again, a brick can only break after being stepped on 3 times over the course of 0.39 seconds, causing breaking to appear largely delayed.
Also note that this will probably cause bricks to break extremely fast since there’s really no cooldown for the Touched event to occur. Consider either increasing the number of cracks required for a brick to break, or switching to a system which destroys bricks with a delay after being touched once.