Delete Item From UI

Hello, I currently have this script that is meant to detect what player pressed a GUI button, detect if a part of the same name as the player exists within a folder, and if true, destroy the part. My problem is that I wish to remove the part from the entire server, while this code (local script) only removes it from the client. If I attempt to do this via regular script, it does not work at all. How may I fix this and thank you.

script.Parent.MouseButton1Click:Connect(function(player)
	for Index, Part in ipairs(workspace.Aircraft:GetDescendants()) do
		if Part.Name == player.Name then
			Part:Destroy()
		end
	end
end)
6 Likes

Just use Remote Event.
Make one and put it on Replicated Storage.

local RemoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function(player)
	for Index, Part in ipairs(workspace.Aircraft:GetDescendants()) do
		if Part.Name == player.Name then
			RemoteEvent:FireServer(Part)
		end
	end
end)

Then it calls the server, and you got to make a Server Script and write your part code deletion, just like this:

local RemoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(PlayerClient, Part))
Part:Destroy()
end)

Learn more about events here, as they are pretty useful when it comes to scripting:

5 Likes

Call a remote, then detect the remote with a server script and destroy the part.

3 Likes

Until an exploiter deletes the entire serveršŸ˜±

5 Likes

That is not quite possible as Roblox added FE(Filtering enabled) protection.

3 Likes

This is the definition of ā€œitā€™s possibleā€.

6 Likes

Mr. GreenGuy, client side cannot access to server script services to change anything.

1 Like

Unfortunately does not work. Gives an error saying ā€œattempt to index nill with nameā€

1 Like

Can you copy me the output or take a screenshot?

1 Like

I know, but your remote event literally opens a gate for that.

1 Like

Iā€™m guessing the problem is from the part variable.
It seems like the script hasnā€™t recognized that variable as PART very well.
Make sure that the variable is your part.
Double check it.

1 Like

I think it does not recognize my player name, and instead gives nill. This is the exact same error that happened before.

1 Like

Yes, sadly as it is possible for client to get access to Replicated Storage, but that requires a protection system as well.
Here it is:

Many posts have talked about this:

https://devforum.roblox.com/t/protecting-remote-events-not-about-remote-hacking-but-about-remote-existence

And like I said, exploiters cannot really do anything:

1 Like

You sure that the parent of the script is a button?
Also try debugging with print(), so you could find out player nameā€¦ part nameā€¦ etc.
Print out those things, it might be helpful.

1 Like

Yes, it is a button. I have also tried printing, and it always stutters at the player name. Gives that ā€œnillā€ error I mentioned.

1 Like

You are missing my point. The exploiter can literally just fire your remote event with whatever model/part they want gone, and boom, destroyed.

That could be solved by just adding some extra security statements when firing the part along with it.
Plus, nobody said this project he is working on is going on public so fast at first time.
They will add extra anti cheatsā€¦ etc, once they are finished.
So what makes you worry about a non-finished script on a private game?

Because the code has a serious security flaw, which you mentioned nothing about, and could have gone unnoticed.

It looks a like a cake.
You got to make the cake first, make it EXIST.
Then you add extra things.
As the topic title said, it requires a help in part deletion, not security stuff.
I believe in the ALPHA version of the project, these bugs, lack of security should be checked.
So not really, it will be noticed.
We have to discuss what part of the script is his PROBLEM.
Not extra things.