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

how do i make this door remove itself after it's used?

Asked by 4 years ago

i am making a door that opens when leaderstats are a certain number, but i also want the door to remove itself after used, so i changed a small part of the code to be line 10, but now the door doesnt work anymore

local Exp = 1

local db = true
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Exp.Value >= Exp then
            if db then
                db = false
                script.parent:remove
            end
        end
    end
end)

how do i fix this?

0
did you try script.Parent:Destroy() MarcTheRubixQb 153 — 4y
0
Well you don't have correct capitalization MarcTheRubixQb 153 — 4y
0
thanks, it works now! CaptainGreenSeals 23 — 4y
0
First of all, when you use functions, you have to add parentheses after the function anem CrypxticDoge 135 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

I see loads of mistakes on your code. Most of everything you put is deprecated. So lemme change some things. I'll put in --comments to show you the mistakes.

local Exp = 1

local db = true
script.Parent.Touched:Connect(function(hit) --connect is deprecated. Use Connect.
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Exp.Value >= Exp then
            if db then
                db = false
                script.parent:Destroy() --remove() is also deprecated. You didn't put the brackets on remove().
            end
        end
    end
end)

If this doesn't work, let me know and I can re-edit the script.

0
If you are destroying the parent of a script it deletes the script with it, you won't need the variable db. JudgeDuckie 25 — 4y
Ad

Answer this question