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

How would I find a specific child determined on it being equal to the parent of a clicked model?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Players = game.Players:GetChildren()
local contraband = player:WaitForChild('Illegal').Contraband
local SearchedPlayer = game.Players:FindFirstChild("Player1")


function SearchPerson()
	if mouse.target ~= nil then
if mouse.target.Parent.Name == SearchedPlayer.Name then
print ('This person is in players')


print ("Searching " ..mouse.Target.Parent.Name .. " for illegal substances")



end
end
end

mouse.Button1Down:connect(SearchPerson)

everything works fine when player1 is in the brackets, but I don't have enough knowledge to figure out how to make it equal to the mouse target parent! I'm stumped! Thank you!!!

1 answer

✓ Accepted answer

Try this it loops through all players inside game.Players, and checks if the NAME is equal.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Players = game.Players:GetChildren()
local contraband = player:WaitForChild('Illegal').Contraband



function SearchPerson()
    if mouse.Target ~= nil then
	for _,v in pairs(game.Players:GetChildren() do
	    if mouse.Target.Parent.Name == v.Name then
		local selectedPlayer = v
		local character = selectedPlayer.Character

	        print ('This person is in players')
	        print ("Searching " ..v.Name .. " for illegal substances")
	    end
	end
    end
end

mouse.Button1Down:connect(SearchPerson)

2 comments

0

Thank you! I have one more question if you are up for it. How would I access this chosen player's leader-stats? is there a way?

0

NEVER MIND I FIGURED IT OUT THANK YOU SO MUCH!!!!

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