Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

4 comments

0

did you try script.Parent:Destroy()

0

Well you don't have correct capitalization

0

thanks, it works now!

0

First of all, when you use functions, you have to add parentheses after the function anem

1 answer

✓ Accepted answer

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.

1 comment

0

If you are destroying the parent of a script it deletes the script with it, you won't need the variable db.

This discussion is preserved as it was. New answers, comments, and votes are closed.