How to check if a Tool has a certain element within it?

I have a give player tool script, but I’m trying to make it so that only Tools with a “Certified” bool value of true have the ability to be given to other players (there’s an issue with gamepass gear being given to players who do not have the gamepass).

The Tool

giveSystem - Roblox Studio 5_22_2021 8_52_28 PM (2)

The Script

local Player = game.Players.LocalPlayer
local HandtoGui = script.Parent.Parent
local NameBox = HandtoGui.Frame.NameBox
local GiveButton = HandtoGui.Frame.GiveButton

local br_ID = 17792178
local mg_ID = 17792695

local function getPlayerFromPartialName(PartialName)
	local foundName = nil
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local PossiblePlayer = Players[i]
		if string.find(string.lower(PossiblePlayer.DisplayName), string.lower(PartialName)) then
			foundName = PossiblePlayer.DisplayName
		end
	end

	if not foundName then
		return nil
	else
		return foundName
	end
end
GiveButton.MouseButton1Click:Connect(function()
	if not Player.Character:FindFirstChildWhichIsA("Tool") then
		NameBox.Text = ""
		NameBox.PlaceholderText = "Equip a drink first!!"
		wait(1)
		NameBox.PlaceholderText = "Player Name Here"
	end
	local NameBoxText = NameBox.Text
	if NameBoxText ~= "" then
		local playerName = getPlayerFromPartialName(NameBoxText)
		if playerName then
			print("Found player")
			game.ReplicatedStorage.GivePlayerItem:FireServer(playerName)
			NameBox.Text = ""
			NameBox.PlaceholderText = "Given!"
			wait(1)
			NameBox.PlaceholderText = "Player Name Here"
		else
			NameBox.Text = ""
			NameBox.PlaceholderText = "Player Not Found!"
			wait(1)
			NameBox.PlaceholderText = "Player Name Here"
		end
	end
end)

Any help is greatly appreciated, thanks!

On the server, you need to do something like this:

if Tool:FindFirstChild("Certified") 
    and Tool.Certified:IsA("BoolValue") 
    and Tool.Certified.Value 
then
  -- give to player
end
1 Like