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

How to make blocks go away, or remove from the game temporarily?

Asked by 4 years ago

So I'm kind of a beginner in scripting, most of my knowledge is from videos on YT so, I'm creating like 3d blocks that charge at the player and do damage, but once the attack is done, how do i make it go away, if i make the transparency 1 to go invisible and turn cancollide off, the damage script will still hit the player, no matter the transparency, so I'm wondering how to remove a part or block from the game temporarily , or make whenever the transparency is 1 it will not hurt the player, any help would be appreciated.

4 answers

Log in to vote
0
Answered by 4 years ago

You'd set the parent equal to nil. This is like using :Destroy() except you can still use the object later.

Ad
Log in to vote
0
Answered by 4 years ago

You can use an if statement to check if the block is invisible. Here's an example:

-- Assume this script is inside the part that damages players

local block = script.Parent

block.Touched:Connect(function(part)
    local humanoid = part.Parent:FindFirstChild('Humanoid')

    if humanoid and block.Transparency ~= 1 then -- checking for humanoid and transparency
        humanoid:TakeDamage(50) -- Edit the value to your liking
    end
end)

line 8 checks if there's a humanoid and also checks the transparency of the block in the same time using 'and'. The '~=' symbol represents 'Not equal to' btw incase you didn't knew.

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago

Rather than setting the parent to nil and losing access to it from another script, simply set it's parent to ReplicatedStorage. This should remove it from the workspace, but it will keep it's stats and everything (position, state, color, etc.). Then you can set ti's parent back to workspace to bring it back.

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

Use

game.Workspace.ITEMNAMEHERE = game.ReplicatedStorage -- whatever here like lighting, replicated storage or something
-- then later you can put
game.ReplicatedStorage.ITEMNAMEHERE = game.workspace

Answer this question