Part not Unanchoring

I have a tornado with the radius on it, and when the radius touches a part called Roof it will unanchor it. Its not unanchoring it however, Its Every roof in the game is stored in a folder, the pathway is workspace.Map.Roofs. If you can help me get the radius to unanchor roofs when it touches it I will be very grateful. Thanks!

function TornadoModule.DamageObjects()
    local Tornado = game:GetService("Workspace").Storms:WaitForChild("Tornado")
    local EFAttribute = Tornado:GetAttribute("EF")
    local Map = game:GetService("Workspace").Map
    local Roofs = Map.Roofs
    local Radius = Tornado:WaitForChild("Radius")

    -- Function to handle roofs flying into the tornado
    local function flyIntoTornado(roof)
        roof.Anchored = false  -- Unanchor the roof
        local distance = (Tornado.Position - roof.Position).Magnitude
        local moveTime = distance / 100  -- Adjust speed based on your preference

        -- Tween the roof towards the tornado
        local tweenInfo = TweenInfo.new(moveTime, Enum.EasingStyle.Linear)
        local goal = { Position = Tornado.Position }
        local tween = game:GetService("TweenService"):Create(roof, tweenInfo, goal)
        tween:Play()
    end
6 Likes

Could you show the code where you touch it please? (event). The functions might not be enough.

3 Likes
    Radius.Touched:Connect(function(hit)
        -- Check if the hit object is a part of the Roofs folder
        local parent = hit.Parent
        if parent and parent:IsDescendantOf(Roofs) and parent:IsA("Model") and parent.Name == "Roof" then
            local roof = parent:FindFirstChildWhichIsA("Part")
            if roof then
                print("Hit!!!!")
                flyIntoTornado(roof)
                roof.Anchored = false
                print("Unanchored")
            end
        end
    end)
end
sorry bout that
2 Likes

When I copy and pasted it it didn’t get the touched function for some reason sorry lol

2 Likes

Have you added a print to see if the touch event fires? Usually two parts touching won’t trigger the touched event unless it’s apart of a character.

Instead you can use Radius:GetTouchingParts() which will return the parts it is touching.

2 Likes

I’ll try that when I get home. I tried it once but I may have the wrong inputs cause I never used it. Do you know which inputs I need to put in to make it work?

2 Likes

To implement it you could use a loop like this:

while task.wait() and Tornado do
   local touching = Tornado:GetTouchingParts()
   for _,part in pairs(touching) do
      local parent = part.Parent
      if parent and parent:IsDescendantOf(Roofs) and parent:IsA("Model") and parent.Name == "Roof" then
            local roof = parent:FindFirstChildWhichIsA("Part")
            if roof then
                print("Hit!!!!")
                flyIntoTornado(roof)
                roof.Anchored = false
                print("Unanchored")
            end
        end
   end
end
3 Likes

I’ll try that. I can’t believe you have 50 mil visits bro congrats.

4 Likes

This would be good if hit detection was really important, but if it’s not i’m sure .Touched would be better. Performance wise.

Also congrats on 50 mil visits, my game barely got over 100.

3 Likes

I take it the touch script isn’t working correctly. In this case for me the 1st step to debug this would be to lower the complexity down to a point anything is working … even if only to test a starting building point. Did a simple version touch … then add in the rest.

This line: parent.Name == “Roof” is the only one I’d use at 1st, without any of the double checking things. As you move up the complexity the problem will become clear.

Stuff like this: if roof then
I would prefer for it to throw an error so that I am aware of it, rather than failing silently.

3 Likes

I agree, I think it would also be beneficial to get rid of the findfirstchild methods FOR NOW. Just so he can see what is working or not.

3 Likes

nothing was printed from this, nor did anything un anchor. The storm also didnt continue moving after the tornado sized which was kinda weird.

3 Likes

Is the tornado unanchored or anchored?

thanks :slight_smile:

4 Likes

well its weird but its anchored for a few script lines to load then once it begins to move in un anchors and is weld constrainted to the funnel cloud

2 Likes

If its un anchored you should still be able to use the touched event, so try this code and lmk if it works:

Radius.Touched:Connect(function(hit)
        print(hit)
        -- Check if the hit object is a part of the Roofs folder
        if hit and hit:IsDescendantOf(Roofs) and hit:IsA("Model") and hit.Name == "Roof" then
            local roof = parent:FindFirstChildWhichIsA("Part")
            if roof then
                print("Hit!!!!")
                flyIntoTornado(roof)
                roof.Anchored = false
                print("Unanchored")
            end
        end
    end)
3 Likes

Ok well the storm continues and moves which is good, but it only prints my character and not the roofs, then doesnt proceed on. Would you like me to show you where each object is placed in?

Ya there? (30charlimitttttttttttttt)

I did an alternative way that would’ve been easier to begin with, just check if the name is in a house model and if it is and the distance is < = radius.Size.x then it will un anchor the roof. Thanks for the help tho!

Great, sorry for not replying I wasn’t home.

Is this in a loop? If so, this may not be the best idea unless like I said before unless the detection is really important.