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

How to make a block I placed disappear?

Asked by 3 years ago

I made a block placing script where the player can place a part, but the part just stays there forever! I need to make it so that the part will disappear after let's say 10 seconds, I have tried so many ways and non of them work, I really am stumped and require help, and I tried putting at the end wait (10) p:destroy but that only works for the first part, every block I place after stays

function place()
    p = Instance.new("Part")
    p.Parent = game.Workspace
    p.Name = game.Players.LocalPlayer.Name
    p.BrickColor = game.Players.LocalPlayer.PlayerGui.Vectors.Color.Value
    if game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 1 then
        p.Anchored = true
    elseif game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 0 then
        p.Anchored = false
    end
    p.Size = game.Players.LocalPlayer.PlayerGui.Vectors.VValue.Value
    p.Position = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
end

script.Parent.Activated:connect(place)

2 answers

Log in to vote
0
Answered by 3 years ago

Have you tried using p:Destroy() when you need to destroy it?

0
Also if you need to wait ten seconds just use wait(10) then the event above Dragon_meck 15 — 3y
0
It just deletes the first block placed, after that every block i place after doesnt get destroyed. DanDan_Potato 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I went ahead and used spawn() which runs a function in a separate thread without yielding the current one. Below is the revised code. Please let me know if it works! I tested it and had no issues. :)

function place()
    p = Instance.new("Part")
    p.Parent = game.Workspace
    p.Name = game.Players.LocalPlayer.Name
    p.BrickColor = game.Players.LocalPlayer.PlayerGui.Vectors.Color.Value
    if game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 1 then
        p.Anchored = true
    elseif game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 0 then
        p.Anchored = false
    end
    p.Size = game.Players.LocalPlayer.PlayerGui.Vectors.VValue.Value
    p.Position = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
end

spawn(function()
    script.Parent.Activated:Connect(place)
end)
0
I'm not sure what this did? The blocks just stay after the i place the first one, the first one does disappear tho DanDan_Potato 0 — 3y

Answer this question