Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script wont delete attachments in certain parts?

Asked by
soutpansa 120
5 years ago
Edited 5 years ago

Im having an issue with this script. It gets the children of the player's character, and then copies them, then it's supposed to get the children of the copies, and delete the Attachments in them but it wont. The attachments stay there and the character gets stuck. Here's my code:

script.Parent.Soru.OnServerEvent:Connect(function(Player, mousehit)
    if SoruCD == 0 and Player.NonStats.Stunned.Value == false and Player.Stats.SoruEXP.Value >= 5000
    and Player.Stats.Stamina.Value >= 250 then
        local Range = 150
        local Distance = (mousehit.p - Player.Character.UpperTorso.Position).Magnitude
        if Distance <= Range then
        SoruCD = 1
        Player.Stats.Stamina.Value = Player.Stats.Stamina.Value - 250
        Player.Character.UpperTorso.soru:Play()
        local direction = (mousehit.p - Player.Character.HumanoidRootPart.Position) * Vector3.new(1, 1, 1);
        direction = CFrame.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position + direction)
        Player.Character.HumanoidRootPart.CFrame = direction
            local Parts = Player.Character:GetChildren()
            for i,v in pairs(Parts) do
            if v.ClassName == "MeshPart"
            then local V = v:Clone()
            V.Parent = workspace
            V.BrickColor = BrickColor.new("Really black")
            V.Transparency = 0.5
            V.Anchored = true
            V.CanCollide = false
            local Attachments = V:GetChildren()
            if Attachments.ClassName == "Attachment" then
            Attachments:Destroy()
            game:GetService("Debris"):AddItem(V, 2) 
            Player.Character.UpperTorso.CFrame = CFrame.new(mousehit.p)*CFrame.new(0,5,0)
            wait(2)
            SoruCD = 0
                    end
                end
            end
        end
    end
end)

any idea what could be causing this? Thanks for reading

3
indent green271 635 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
local Attachments = V:GetChildren()
if Attachments.ClassName == "Attachment" then

Attachments is a table of children, and you're forgetting to loop over it.

0
Show the fixed code for it. xPolarium 1388 — 5y
2
No need in this case, the OP knows how to loop over a table of children, it's exactly what they are doing for the Parts table. It's one of those facepalm mistakes. EmilyBendsSpace 1025 — 5y
0
I actually tried a loop like that and it didn't work lol soutpansa 120 — 5y
0
It *does* work, you just did it wrong or through your very messy code you couldn't see it. User#24403 69 — 5y
0
There is probably just another bug. For example, if the `if Attachments.ClassName == "Attachment" then` clause was actually being entered, the wait(2) inside would make this whole function take at least 2 seconds per MeshPart, or even worse if it ended up inside the attachments deletion loop! Probably the wait is supposed to be outside the loop? EmilyBendsSpace 1025 — 5y
Ad

Answer this question