Ship Delete Button

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.
image

Finally, here is an image of the script ‘GUI’, where the ScreenGUI is put into the player.

I’m quite new to this stuff so any and all help would be appreciated! Thank you

1 Like

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?

No because the ScreenGUI isnt in the ship model anymore, it got put into the playerGUI.

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.

script.Parent.Parent is the ship.

Ill have a go, but im sure ive already tried that

The jump works, but I get this error when trying to delete the main model:

image

Here’s the script
image

Here’s the indentation in the model, Im 90% sure I put the right amount of "parent"s
image

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.

1 Like

create a remote event, and make a server-side script that listens for the event, and add the boat in the argument then delete it.

RemoteEvent.OnServerEvent:Connect(function(Boat)
  Boat:Destroy()
end)

Question - do remoteevents have to be in RepStorage or can they be in a folder in the ship model?

Nvm just saw it in the documentation you send lol