Still have questions? Join our Discord server and get real time help.
0

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

Paldi 109
3 years ago
Edited 3 years ago

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)


0
Pyrondon 2089
3 years ago

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