Sorry for the horrible code.
I want the game to listen out for objects stored in my serverstorage (table), and when someone calls it out it spawns it in game. At the moment it prints twice and it's always nil.
local chat = game:GetService("Chat") adjectives = {""} objects = game.ServerStorage:GetChildren() local Players = game:GetService("Players") game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoidRootPart = character:WaitForChild("HumanoidRootPart") player.Chatted:Connect(function(msg) for _,v in ipairs(objects) do local cool = table.find(objects, msg) print(cool, "|" .. msg) if msg == cool then Instance.new("Part",game.Workspace) end --local clone = msg:Clone() --clone.Parent = game.Workspace --clone.Position = humanoidRootPart.Position end end) end) end)
my explorer/output:
https://i.imgur.com/iXPVoNx.png
thanks!
Try changing local cool = table.find(objects, msg)
to local cool = game.ServerStorage:FindFirstChild(msg)
local chat = game:GetService("Chat") adjectives = {""} local Players = game:GetService("Players") local ServerStorage = game:GetService("ServerStorage") Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoidRootPart = character:WaitForChild("HumanoidRootPart") player.Chatted:Connect(function(msg) local cool = ServerStorage:FindFirstChild(msg) print(cool, "|" .. msg) if cool ~= nil then Instance.new("Part", workspace) end -- local clone = cool:Clone() -- clone.Parent = game.Workspace -- clone.Position = humanoidRootPart.Position end) end) end)
'ServerScriptService' and 'ServerStorage' seems to be fine.
I see you're up to something.
When i was making 'stand on part or click to popup a TextLabel', i changed the time and it worked finally perfectly!
So if you are up to it put 'something' like wait (0.5) in it!
Try doing this.
local chat = game:GetService("Chat") adjectives = {""} objects = game.ServerStorage:GetChildren() local Players = game:GetService("Players") game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoidRootPart = character:WaitForChild("HumanoidRootPart") player.Chatted:Connect(function(msg) for i,v in pairs(objects) do if msg == objects[v] then print(objects[v].."|" ..msg) Instance.new("Part",game.Workspace) else print("No Match") end --local clone = msg:Clone() --clone.Parent = game.Workspace --clone.Position = humanoidRootPart.Position end end) end) end)
I had this exact issue a few years ago.
Try replacing table.find(objects, msg)
with table.find(objects, msg:gsub("\r", ""))
.
Though, as someone else already answered to this post – I recommend using :FindFirstChild()
instead of using a table.