hi, so I have a script which uses script.find
to search players inventory and character for a specific tool however, even tho the script refuses to return true
After debugging it turns out that the tool which string.find is seraching for is indeed included in the for loop
local TriggerPart = script.Parent.TriggerPart.ProximityPrompt
local ServerStorage = game:GetService("ServerStorage")
local NotificationEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SendNotificationEvent")
local function CheckPlayerInventory(player)
local playerHasAnItem = false
-- Check the player's Backpack
for _, item in pairs(player.Backpack:GetChildren()) do
print("Checking Backpack: " .. item.Name)
if string.find(item.Name, "SCP-2923") then
warn("Player already has SCP-2923 in Backpack: " .. item.Name)
playerHasAnItem = true
break -- Exit loop early if the item is found
end
end
-- Only check the Character if the item wasn't found in the Backpack
if not playerHasAnItem then
for _, item in pairs(player.Character:GetChildren()) do
print("Checking Character: " .. item.Name)
if string.find(item.Name, "SCP-2923") then
warn("Player already has SCP-2923 equipped: " .. item.Name)
playerHasAnItem = true
break -- Exit loop early if the item is found
end
end
end
-- Log final status
if playerHasAnItem then
print("Player item detected")
return true
else
print("Player doesn't have item")
return false
end
end
TriggerPart.Triggered:Connect(function(player)
local PlayerHasAnItem = CheckPlayerInventory(player)
warn(tostring(PlayerHasAnItem))
if PlayerHasAnItem == true then
NotificationEvent:FireClient(player, "Action Prohibited", "You already have SCP-2923", 3)
else
NotificationEvent:FireClient(player, "Notification", "You picked up a strange Protein Bar", 3)
end
end)
Here is an output from line 12 proving that an item with said name does exist.
My question is why is the script returning false?
Edit: Fixed formatting of the message