-
What do you want to achieve? Keep it simple and clear!
I would like to make a stability system like from this video : https://www.youtube.com/watch?v=FrYwXCN_TRI&t=208s at 3:24. I need a script to detect when a structure gets destroyed then to check if any other connections are available for the structures above it to be held up by and if not then destroy everything. -
What is the issue? Include screenshots / videos if possible!
I can’t seem to get it working. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried raycasting but it is not effective in this situation because that just removes everything above the destroyed structure and it doesn’t check to see if another structure is holding everything up. I have looked on DevForum and on YouTube for solutions but there was nothing so I decided to create this post.
Here is my script, it is a server script in my “Builds” folder in workspace.
local BuildsFolder = script.Parent
local connections = {}
function isConnectionExist(Structure, Attachment1, Attachment2)
for _, connection in pairs(connections) do
if connection.Structure == Structure then
if (connection.Attachment1 == Attachment1 and connection.Attachment2 == Attachment2) or (connection.Attachment1 == Attachment2 and connection.Attachment2 == Attachment1) then
return true
end
end
end
return false
end
function removeConnection(Structure)
for i, connection in ipairs(connections) do
if connection.Structure == Structure then
table.remove(connections, i)
break
end
end
end
BuildsFolder.ChildAdded:Connect(function(NewStructure)
for i, v in pairs(NewStructure:GetDescendants()) do
if v:IsA("ObjectValue") and v.Value ~= nil and v.Name == "AttachmentThatIsAttachedToThis" then
local Health = NewStructure:FindFirstChild("Health")
local Attachment1 = v.Parent
for i, v2 in pairs(BuildsFolder:GetDescendants()) do
if v2 == v.Value then
local Attachment2 = v2
if not isConnectionExist(NewStructure, Attachment1, Attachment2) then
table.insert(connections, {Structure = NewStructure, Attachment1 = Attachment1, Attachment2 = Attachment2})
print("Added connection : ", connections)
end
Health:GetPropertyChangedSignal("Value"):Connect(function()
if Health.Value <= 0 then
if isConnectionExist(NewStructure, Attachment1, Attachment2) then
removeConnection(NewStructure)
print("Removed connection : ", connections)
end
end
end)
end
end
end
end
end)
Each structure has a bunch of values in them but I’m just going to list the important ones. They are “Health” and “Stability” which are IntValues. Then the structure has attachments in the different parts for the snapping feature like from Rust and each attachment has an ObjectValue in it named “AttachmentThatIsAttachedToThis” and the value of that gets set to the attachment its being attached to with a server script that handles the placement. Also the attachment its being attached to ALSO has an “AttachmentThatIsAttachedToThis” ObjectValue in it so it keeps track of which attachments are attached to what. Also each attachment has an attribute named “Placed” for the snapping system so it can check if it has been placed. So technically it shouldn’t be too hard to make the stability system but for some reason I can’t seem to get it working. The script works perfectly by the way, it prints the table after every placement and it has the right attachments and structure names in it and then removes it when the structure’s health dips below 0 or is equal to 0 and I use my destroy tool to set the health to 0 for testing. Any ideas would be lots of help to me, I just need the idea of how I could achieve this and then I can most likely script it myself.