Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

table of items that i shouldn't be able to click on?

Hello, i'm trying to make a tool that when i click somewhere it does something but i want it to not do that thing when the parent of the mouse target is in the restricted table the thing is how it is now, i can still click on the restricted.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local restricted = {"model1","randommodel","etc","stuff"}

mouse.Button1Down:Connect(function ()
	for i,v in pairs(restricted) do
		if mouse.Target.Parent.Name ~= v then
			--some thing..
		end
	end
end)

1 answer

The actions need to be performed if and only if the name isn't equal to any of those, so you need to perform the check before doing "some thing..":

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local restricted = {"model1","randommodel","etc","stuff"}

mouse.Button1Down:Connect(function()
	if mouse.Target then --// Make sure you check if mouse.Target exists, first and foremost.
		local found;
		for _,v in pairs(restricted) do
			if mouse.Target.Parent.Name == v then
				found = true;
				break;
			end
		end
		if not found then
			-- Something..
		end;
	end
end)

Hope this helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.