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

How to make a part appear, disappear and then reappear again?

Asked by 5 years ago

So, before I was trying to make a part appear in the workspace and then disappear. It clearly didn't work before but now it does (thanks to moo1210 for explaining it to me). But now, I want to make the part reappear again after it destroyed itself from the workspace. It didn't work, instead it gives me an error saying, " 13:55:55.919 - The Parent property of JumpBoost is locked, current parent: NULL, new parent Workspace". Here's my script (it is located in the ServerScriptService):

local jumpBoost = game.ReplicatedStorage:FindFirstChild("JumpBoost")
local clonedJumpBoost = jumpBoost:Clone()
clonedJumpBoost.Parent = workspace
local boostedJumpPower = 100
local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
        clonedJumpBoost.CanCollide = false
        local currentJumpPower = humanoid.JumpPower
        if currentJumpPower < boostedJumpPower then
            humanoid.JumpPower = boostedJumpPower
            clonedJumpBoost:Destroy()
            wait(5)
            if clonedJumpBoost.Parent ~= workspace then
                clonedJumpBoost.Parent = workspace
            end
            humanoid.JumpPower = currentJumpPower
        end
    end
end
clonedJumpBoost.Touched:Connect(onPartTouch)
0
just change its transparency WideSteal321 773 — 5y
0
okay thx for telling me imadurtbag 2 — 5y

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Repeatedly eliminating an instance will cause it’s Parent to lock, if you’re destroying more than one descendant of a Parent at once or the same multiple times, it will lead to this event, switch to :Remove() or switching the form of your statement:

workspace:WaitForChild("JumpBoost"):Destroy()

This problem could also just be accustom to the Server it’s running in, this could be solved if you save your code, quit Studio, reopen, and put your Script back in. ROBLOX has been having quite a few Engine issues lately

Hope this helps, if so, press accept answe and upvote!

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

So, I followed your advice @simplealgorithm but it still didn't work and it gives me the same error. Here's my script:

local jumpBoost = game.ReplicatedStorage:FindFirstChild("JumpBoost")
local clonedJumpBoost = jumpBoost:Clone()
clonedJumpBoost.Parent = workspace
local boostedJumpPower = 100
local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
        clonedJumpBoost.CanCollide = false
        local currentJumpPower = humanoid.JumpPower
        if currentJumpPower < boostedJumpPower then
            humanoid.JumpPower = boostedJumpPower
            workspace:WaitForChild("JumpBoost"):Destroy()
            wait(5)
            if clonedJumpBoost.Parent ~= workspace then
                clonedJumpBoost.Parent = workspace
            end
            humanoid.JumpPower = currentJumpPower
        end
    end
end
clonedJumpBoost.Touched:Connect(onPartTouch)

Also, I tried using :Remove(), fortunately, it did remove the part and put it back in the workspace, however, the part didn't seem to disappear when I step on it anymore and it also didn't give me a jumpboost. Here's the script with the :Remove() function:

local jumpBoost = game.ReplicatedStorage:FindFirstChild("JumpBoost")
local clonedJumpBoost = jumpBoost:Clone()
clonedJumpBoost.Parent = workspace
local boostedJumpPower = 100
local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
        clonedJumpBoost.CanCollide = false
        local currentJumpPower = humanoid.JumpPower
        if currentJumpPower < boostedJumpPower then
            humanoid.JumpPower = boostedJumpPower
            clonedJumpBoost:Remove()
            wait(5)
            if clonedJumpBoost.Parent ~= workspace then
                clonedJumpBoost.Parent = workspace
            end
            humanoid.JumpPower = currentJumpPower
        end
    end
end
clonedJumpBoost.Touched:Connect(onPartTouch)

Answer this question