Hello again, I have a problem when I often click with the mouse the string and its components are not destroyed I have to do it very slowly, I have the variable clicked on false then within the function I set it to true, the string is triggered and create the components then in elseif I have it put true and then false, I put the script there is no better method to do this?
if Clicked == false and Mouse.Target ~= nil and character:WaitForChild('HumanoidRootPart') then
Clicked = true
local Pos = Mouse.Hit.p
if character:FindFirstChild('HumanoidRootPart') then
local Sound = Instance.new('Sound',character:WaitForChild('HumanoidRootPart'))
Sound.SoundId = 'rbxassetid://231731980'
Sound:Play()
wait(1)
Sound:Destroy()
end
ancla = Instance.new('Part',workspace)
ancla.Name = "ancla"
ancla.Size = Vector3.new(1,1,1)
ancla.Transparency = 1
ancla.Anchored = true
ancla.CanCollide = false
ancla.CFrame = CFrame.new(Pos)
Att0 = Instance.new('Attachment',character:WaitForChild('HumanoidRootPart'))
Att1 = Instance.new('Attachment',ancla)
rope = Instance.new('RopeConstraint',character:WaitForChild('HumanoidRootPart'))
rope.Color = BrickColor.new('Really black')
rope.Visible = true
rope.Length = (character.Torso.Position - ancla.Position).magnitude
rope.Attachment0 = Att0
rope.Attachment1 = Att1
forceAncla = Instance.new("BodyVelocity", character:WaitForChild('HumanoidRootPart'))
forceAncla.Name = "VelAncla"
while forceAncla ~= nil and wait() do
forceAncla.MaxForce = Camera.CFrame.lookVector * Vector3.new(10000,0,10000)
forceAncla.Velocity = Camera.CFrame.lookVector * Vector3.new(10000,0,10000)
rope.Length = rope.Length - 5
RunService.RenderStepped:Wait(1)
end
elseif Clicked == true then
Clicked = false
if Att0 and Att1 and ancla and rope and forceAncla then
Att0:Destroy()
Att1:Destroy()
ancla:Destroy()
rope:Destroy()
forceAncla:Destroy()
end
end
I also put the complete script. https://pastebin.com/730A5996

1 comment
I spent the whole afternoon trying to solve it and I solved it, it was the wait (1) after Sound and I put the sound of destroying the Sound in its place where I destroy the other objects. I am sorry and thank you.