Clicked Event issues

Hi, i’m trying to make it so that if the player has the InRange tag and clicks anywhere on screen, a row of Lasers will be destroyed. Here is my code

local handle = script.Parent:WaitForChild("Handle")

script.Parent.Click.OnServerEvent:Connect(function(plr,target)
	local Map = game.Workspace:FindFirstChild("Map")
	local LaserRoom2 = Map:FindFirstChild("LaserRoom2")
	local Player = game:GetService("Players")
	
	if Player:FindFirstChild("InRange") then
		for i, v in pairs(LaserRoom2.Lazers:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "Lazer" then
				v.Destroy()
			end
		end
	end
end)

I believe you are using the wrong Variable here. That would search player’s names, not 1 player.

	local Player = game:GetService("Players")
	if Player:FindFirstChild("InRange") then
        --Same as
       if game.Players:FindFirstChild("InRange") then

should I do local Player = game.Players;GetPlayers()?

That didn’t do anything. What’s wrong with it? There aren’t any errors

If your trying to see if the one player through the event clicked it do:

if game.Players[plr]:FindFirstChild("InRange") then
--Might be [plr.Name] if it doesn't work

Still did not work. No errors occured

if plr:FindFirstChild("InRange") then

Still, nothing occurred. This is very odd

What do you mean by Tag? What kind of data is it? BoolValue, StringValue, IntValue, a Folder? We need to know more about the InRange Instance… Is it from the CollectionService? How are we suppose to guess.

It is a stringvalue that is inserted into the player.

Okay add some debug print statements real quick like this.

	if plr:FindFirstChild("InRange") then
        print("case 1")
		for i, v in pairs(LaserRoom2.Lazers:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "Lazer" then
                print("case 2")
				v.Destroy()
			end
		end
	end

In the debugger output what does it say?

huh, it now works. I think it may be this line

Okay I’m glad you figured it out.