I need help with script

I am trying to make a script that will unlock a button to teleport. I unselected selectable under property’s and I could still select it. When you click it it does disapear
If you want my code here it is

function OnClicked() 
	script.Parent.Parent.Parent.Parent:Remove()
	script.Parent.Parent.Parent.Parent.Parent.Selectable = true
end 

script.Parent.MouseButton1Down:connect(OnClicked)
1 Like


.Selectable has nothing to do with what you’re trying to do. You can just hide the button when you don’t want players to click on it via .Visible

1 Like

try use “:Destroy()” for delete the part or object

2 Likes

How does the player unlock the teleport functionality?

Regardless, here is a sample of what you’d want to do (based on what you provided as your desire/goal)

local plr = game.Players.LocalPlayer

function OnClicked() 
	script.Parent.Parent.Parent.Parent:Remove()
    plr.Character.HumanoidRootPart.Position = —Use Vector3 or CFrame to change the position of the player

end 

script.Parent.MouseButton1Down:Connect(OnClicked)

Create an if then statement between the function OnClicked() and script.parent.parent.parent.parent:Remove() to check if the player has the requirement (if there is a requirement).

I believe connect() is depreciated in favor of Connect() so I changed it.

There are differences between Remove() and Destroy() in which remove sets the parent to nil while Destroy sets the parent to nil, disconnects all connections on the object’s events, and locks the parent property. Depending on your use of the button, you’d want to choose from these two options.

I can provide a better code sample, but I need to know if the teleport has a requirement.

I tried doing this with the button as the child and it did not work

function OnClicked() 
	script.Parent.Parent.Parent:Remove()
	script.child.visable = true
end 

script.Parent.MouseButton1Down:connect(OnClicked)