so basically im making a snow script where literally everything that touches it leaves an imprint via part:SubtractAsync() buuuuut it for some reason isnt working, I read the api reference and still dont know what im doing wrong, even when i hook up a print command like this: print(hit.ClassName) on the Touched() function and it always printed Part. Please help.
script:
local part = script.Parent.SnowPart
part.Touched:Connect(function(hit)
local newUnion = part:SubtractAsync({hit})
part:Destroy()
newUnion.Parent = script.Parent
end)
local part = script.Parent.SnowPart
part.Touched:Connect(function(hit)
local newUnion = part:SubtractAsync({hit})
part:Destroy()
newUnion.Parent = script.Parent
part = newUnion
end)
but it still has the same exact error. speaking of i forgot to put this in the OP but this is the error.
Right, that’ll happen if a mesh-part, union, or anything else that touches it. Also your solution still won’t work since it wouldn’t repeat. The variable being set is good, but the function was attached to that specific Instance, thus it needs to be set again for the new one. It’d also be wise to put a debounce in there so the game won’t lag out horribly from trying to subtract from a Union 100 times in a second. Here’s how it should look:
local Part = script.Parent.Brick --or whatever part you're getting
local Debounce = false
local OnTouch OnTouch = function(Hit)
local Allowed = Hit:IsA("Part") or Hit:IsA("WedgePart") or Hit:IsA("CornerWedgePart") or false
if not Allowed or Debounce then return end
Debounce = true
local newUnion = Part:SubtractAsync({Hit})
Part:Destroy()
Part = newUnion
Part.Parent = script.Parent
Part.Touched:Connect(OnTouch)
delay(1,function() Debounce = false end)
end
Part.Touched:Connect(OnTouch)
Tested it in Studio and seems to work just fine. Maybe there’s a more efficient way to set this up, but if it works it works.
That’s the exact script I’m using, so it wouldn’t be any different due to a rblx file.
Just what exactly are you forcing the part to touch that’s causing the error?
Well it plainly can’t work with everything. Only certain parts are capable of doing this, as per the error states, Only blocks, spheres, cylinders, wedges and corner-wedges are currently supported.
No need cause it works now! Final script is here for anyone else having similar problems. Thanks ShadukoSan!
local Part = script.Parent.SnowPart --or whatever part you're getting
local Debounce = false
local OnTouch OnTouch = function(Hit)
if Hit.Name ~= "Left Leg" and Hit.Name ~= "Right Leg" then return end
local Allowed = Hit:IsA("Part") or Hit:IsA("WedgePart") or Hit:IsA("CornerWedgePart") or false
if not Allowed or Debounce then return end
Debounce = true
local newUnion = Part:SubtractAsync({Hit})
Part:Destroy()
Part = newUnion
Part.Parent = script.Parent
Part.Touched:Connect(OnTouch)
delay(0,function() Debounce = false end)
end
Part.Touched:Connect(OnTouch)