I want this to print (“dog”) if the tool the player is holding’s tooltip says “M1911”, etc. But im getting an error saying TOolTip not a valid member of part, any help?
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = workspace[hit.Parent.Name] --Access character from workspace.
local player = game.Players:GetPlayerFromCharacter(plr) --Access (plr)
local Tools = plr:GetChildren()
for i = 1, #Tools do
if Tools[i].ClassName == Tools[i].ToolTip == "M1911" or Tools[i].ClassName == "Glock" and Tools[i].ToolTip == "Rossi" then
print("dog")
end
end
end
end)
Tools here is every child of the Character that hit the part, this is going to include more than just tools.
Try
local children = plr:GetChildren()
for i, v in pairs(children) do
if v:IsA("Tool") then
if v.ToolTip == "M1911" then -- add more conditions if necessary
print("dog")
end
else
print(string.format("%s is not a Tool!", v.Name))
end
end
This is giving me the same error as before when trying to add more.
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = workspace[hit.Parent.Name] --Access character from workspace.
local player = game.Players:GetPlayerFromCharacter(plr) --Access (plr)
local children = plr:GetChildren()
for i, v in pairs(children) do
if v:IsA("Tool") and v.ToolTip == "M1911" or v.ToolTip == "Glock" then -- add more conditions if necessary
print("dog")
end
end
end
end)
@ThousandDegreeKnife
That’s a very good point that I hadn’t considered. (not much experience with player backpacks…)
Here’s a modified script that uses a hardcoded list of valid tooltip strings. When the part is touched, it checks the character for a Tool. If it finds one, it checks if the tool’s ToolTip is valid. If it is, it will print to the console.
local ValidItemToolTips = {"M1911", "Gun"}
local debounce = false
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil and not debounce then
local character = humanoid.Parent
local objectsInPlayer = character:GetChildren()
for i, item in pairs(objectsInPlayer) do
if item:IsA("Tool") then
debounce = true
for _, tooltip in pairs(ValidItemToolTips) do
if tooltip == item.ToolTip then
print(string.format("%s with ToolTip %s is a valid item!", item.Name, tooltip))
end
end
wait(2)
debounce = false
end
end
end
end)