Hey. I'm trying to create a script where you type the name of the object and it does something with it, instead of typing the exact location.

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Scripts = RS:WaitForChild("Scripts")
local Remotes = RS:WaitForChild("Remotes")

local Event = Remotes:WaitForChild("Print")

Event.OnServerInvoke:connect(function(Object)
	for _, Obj in pairs(game:GetDescendants()) do
		if Obj.Name == Object then
			print(Obj.Name)
		end
	end
end)

I know there isn't errors, but the script usually breaks if 2+ objects have the same name. I want to know if it's possible to find an object without the exact location and not have the script break.

I know this might be a dumb question, but since I'm new to scripting I don't know how to do this.

2 comments

0

just add a "break" inside the check, it will only work for 1 of the objects

0

Thank you!