How would i make this?
This is a pretty important part for my game because there will be a giant explosion and a part will grow so i want it so if that part touches any other parts or models that it will un anchor that part it touched i dont know how to make this ive tried to look it up but i cant find anything.
The following script put inside the expanding part should do:
script.Parent.Touched:Connect(function(part)
part.Anchored = false
end)
You could also try the following script:
--The following script has a couple of extra things, just to prevent errors.
script.Parent.Touched:Connect(function(part)) --When script.Parent is touched, run the function. "part" would be what touched it
if part:IsA("BasePart") or part:IsA("UnionOperation") then --Just make sure that it is indeed a part, I don't know what else it could be but better safe than sorry
part.Anchored = false
end
end)
Didnt seem to work i dont know why it wouldnt the part is growing via a tween if that helps any its also a sphere
THIS SCRIPT MAY NOT WORK, I don’t work with :GetTouchingParts() ever so yeah.
Hmm, alright
You can try this:
local size = script.Parent.Size
while true do
if size ~= script.Parent.Size then
for i, v in pairs(script.Parent:GetTouchingParts()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") then
v.Anchored = false
end
end
end
size = script.Parent.Size
wait()
end
This script will instead repeat very fast, and if it detects a change in size it will loop through all parts that are touching the script’s parent, changing them all to unanchored
Does the part is involved with a tween?
It worked a little to well and un anchored itself
Uh what do you mean? Like the growing part?
oops I can change that…
try:
local size = script.Parent.Size
while true do
if size ~= script.Parent.Size then
for i, v in pairs(script.Parent:GetTouchingParts()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") then
if v ~= script.Parent then
v.Anchored = false
end
end
end
end
size = script.Parent.Size
wait()
end
I have no idea what happened to the indents…
It worked! But its ultra laggy i dont think therea way to fix that since its having to deal with so much physics but thanks!
Alright, how about
local size = script.Parent.Size
local activeParts = {}
while true do
if size ~= script.Parent.Size then
for i, v in pairs(script.Parent:GetTouchingParts()) do
if not table.Find(activeParts, v) then
table.Insert(activeParts, v)
if v:IsA("BasePart") or v:IsA("UnionOperation") then
if v ~= script.Parent then
v.Anchored = false
--Optionally you can put another wait() here
end
end
end
end
end
size = script.Parent.Size
wait() --Put a number like 0.1 inside the brackets to reduce lag further
end
Basically I put all objects that have already been modified by the script in a table so it knows not to do it again.
I put a couple of comments in the script as well, where you can add a delay
It says it attempted to call a nill value on if not table.Find(activeParts, v) then
Try lowercase find
So it would be table.find(activeParts, v)
Worked just has to put another lowercase thing on insert then it worked still laggy though but when i do that extra wait it doesnt lag but i have noticed it doesnt un anchor all of the parts if i put the extra wait if i dont put it it un anchors all of them if u put it doesnt