Hi! I’m developing a shipping game, and i’m working on the control UI. I am having some difficulty in making a ‘delete’ button, since the UI is put inside of the player, and its trying to delete something in the workspace.
Attached is an image of the UI. The Delete Button is a TextButton, and is the red button at the bottom of the UI.
Below is an image of the model’s layout in Workspace, please take into account that multiple people might spawn the same type of boat so they’d have the same name in the workspace.
Finally, here is an image of the script ‘GUI’, where the ScreenGUI is put into the player.
I’m a little confused on what you’re asking for, but if you’re asking for the button to delete the ship, then you can simply just listen to the button’s click event (Button.MouseButton1Click:Connect()), and then do script.Parent.Parent:Destroy(), unless I’m missing something?
It doesn’t matter where the GUI is. As long as you have a variable that references to it, you can access it from that variable.
In the block where you clone it to the PlayerGui:
GuiClone.DeleteButton.MouseButton1Click:Connect(function()
-- Unseat the player
script.Parent.Parent:Destroy()
end)
I get that I can just put "local ship = game.Workspace[“NKL-27”], but multiple players might spawn the same boat so how would the script know which to delete
The script knows which one to delete, because it’s IN the one to delete.
I just gave you the code to delete the boat the script is under, there’s no need to make another variable to get the boat to delete.
This won’t work if the script is moved from under the boat. Why not just listen for the button click from the main GUI script? That would be much easier.