Basically.
It will greet you if you walk to him this one works.
But if you say the tool name ex: Water it doesn’t give it somewhy and I can’t find the issue.
I also have alot of sorts water so it just gives one sort everytime but I have like 5 sorts.
local Head = script.Parent
local DetectPart = script.Parent:WaitForChild("DetectedPart")
local ServerStorage = game:GetService("ServerStorage")
local ChatService = game:GetService("Chat")
local TouchedPlayers = {}
local Cooldowns = {}
DetectPart.Touched:Connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local playerName = player.Name
if not table.find(TouchedPlayers, playerName) and (not Cooldowns[playerName] or os.time() - Cooldowns[playerName] >= 5) then
ChatService:Chat(Head, "Welcome "..playerName.."! What would you like today?")
table.insert(TouchedPlayers, playerName)
Cooldowns[playerName] = os.time()
end
end
end)
DetectPart.TouchEnded:Connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local playerName = player.Name
local index = table.find(TouchedPlayers, playerName)
if index then
table.remove(TouchedPlayers, index)
end
end
end)
-- Function to find a tool by partial name
function findToolByPartialName(partialName)
for _, item in pairs(ServerStorage:GetChildren()) do
if string.match(string.lower(item.Name), string.lower(partialName)) then
return item
end
end
return nil
end
-- Function to extract tool name from the player's message
function extractToolFromMessage(msg)
local words = string.split(msg, " ")
-- Loop through all words in the message to find the tool name
for _, word in pairs(words) do
local foundTool = findToolByPartialName(word)
if foundTool then
return foundTool
end
end
return nil
end
local greetings = {"hi", "hello", "sup", "hey", "yo", "greetings", "what's up"}
local greetingsai = {"Hello!", "Hi!", "Sup!", "Hey there!", "Greetings!", "What's up?"}
function isGreeting(msg)
local lowerMsg = msg:lower()
for _, greeting in pairs(greetings) do
if lowerMsg == greeting or lowerMsg:match("^" .. greeting) then
return true
end
end
return false
end
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Msg)
if table.find(TouchedPlayers, Player.Name) then
if isGreeting(Msg) then
local function getRandomGreeting()
return greetingsai[math.random(1, #greetingsai)]
end
ChatService:Chat(Head, getRandomGreeting())
return
end
local foundTool = extractToolFromMessage(Msg)
if foundTool then
if foundTool.Name == "Economy" or foundTool.Name == "Frequent Flyer" or foundTool.Name == "Galactic VIP" or foundTool.Name == "Drinks and Snacks Menu" then
ChatService:Chat(Head, "Sorry, I couldn't find the item you're looking for. Please make sure to enter the name exactly as it appears in the menu.")
else
foundTool:Clone().Parent = Player.Backpack
end
else
ChatService:Chat(Head, "Sorry, I couldn't find the item you're looking for. Please make sure to enter the name exactly as it appears in the menu.")
end
end
end)
end)
It sometimes gives me something but not always.
All the tools are inside of Serverstorage.