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.
You'd set the parent equal to nil. This is like using :Destroy() except you can still use the object later.
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.
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.
Use
game.Workspace.ITEMNAMEHERE = game.ReplicatedStorage -- whatever here like lighting, replicated storage or something -- then later you can put game.ReplicatedStorage.ITEMNAMEHERE = game.workspace