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

Why isn't the part disappearing?

Asked by 7 years ago

I have the game.Debris:AddItem thing, so why isn't it working? Here's my script:

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if  input.KeyCode == Enum.KeyCode.C then
script.Disabled = true
    local anim = Instance.new("Animation")
anim.AnimationId = 'rbxassetid://864612571'
local loadanim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
loadanim:Play()
local x = Instance.new("Part", workspace)
    x.Anchored = false
    x.CanCollide = false
    x.Parent = player.Character.RightHand
    x.Material = "Neon"
    x.Transparency = 1
    x.Size = Vector3.new(0.2,0.2,0.2)
    x.BrickColor = BrickColor.new("Cyan")
    x.CFrame = player.Character.RightHand.CFrame*CFrame.new(0,0,0)
local weld = Instance.new("Weld", x)
weld.Part0 = x
weld.Part1 = game.Players.LocalPlayer.Character["RightHand"]
local aa = script.particle1:Clone()
aa.Parent = x
x.Touched:connect(function(Hit)
if Hit.Parent:findFirstChild("Humanoid") and Hit.Parent.Humanoid ~= player.Character.Humanoid then
   Hit.Parent.Humanoid:TakeDamage(90)
x:Destroy()
game.Debris:AddItem(x,0.8)
end
wait(1)
script.Disabled = false
end)
end
end)

1 answer

Log in to vote
0
Answered by 7 years ago

Reading through it seems that you add the part to the debris service in an if statement

if Hit.Parent:findFirstChild("Humanoid") and Hit.Parent.Humanoid ~= player.Character.Humanoid

    Hit.Parent.Humanoid:TakeDamage(
    x:Destroy()
    game.Debris:AddItem(x,0.8)

            end

This means that if the IF function doesn't fire either due to a coding error or any other reason, the part is not added to the debris service and will not dissapear.

Try adding a print() before it to see if it's actually firing.

if Hit.Parent:findFirstChild("Humanoid") and Hit.Parent.Humanoid ~= player.Character.Humanoid

    Hit.Parent.Humanoid:TakeDamage(
    x:Destroy()
    game.Debris:AddItem(x,0.8)

    print("x added to debris.")

            end

I also noticed that you're using Destroy() on the part before adding it to the debris service. If this doesn't throw an error then chances are the entire IF statement isn't firing at all.

Add a buttload of prints wherever there are issues, and get back to me if this solves none of them.

If all that fails then hait could be that this:

script.Disabled = true

Completely stops the script from running. Try adding a print at the end, i.e.:

    Hit.Parent.Humanoid:TakeDamage(90)
x:Destroy()
game.Debris:AddItem(x,0.8)
end
wait(1)
script.Disabled = false

print("Ran successfully")

end)end
end)

If this doesn't print then your disabling the script stopped it from running the code as a whole.

If this is the case the use a debounce.

Otherwise

0
If you copied this script then stop developing BlackOrange3343 2676 — 7y
0
i didnt copy it ;-; izanagi456 4 — 7y
Ad

Answer this question