I attempted to make a script where when you said specific word in the chat, the script changes the Can collide along with the transparency to the brick. However, the script seems to not work, how come?
Brick= game.Workspace.Part Filtered = {"Word"} game.Players.PlayerAdded:connect(function(p) p.Chatted:connect(function(msg) for i,v in pairs(Filtered) do if string.find(msg:lower(), v:lower()) then function onButtonClicked() Brick.CanCollide = false Brick.Transparency = 1 end
A function is a set-aside scope of instructions for the Lua Compiler to execute when called upon. This of which you did not do. To call a function, you must write it's handle alongside the arugmental parentheses:
function onButtonClicked() Brick.CanCollide = false Brick.Transparency = 1 end onButtonClicked()
However, even though this will solve the issue above, to use this is entirely unnecessary, as we can simply just have the two instructive lines run automatically when the conditional—if statement—proves True.
With that out of the way, your issues still do not stop here. You're missing several closures to multiple scopes, which will toss a load EOF
exceptions, ensure to use the end
keyword where necessary, though Intellisense should've already put these measures in place when programming, including automatic indentation. There are also some deprecated methods such as lowercase :connect()
.
local Players = game:GetService("Players") local FindWords = {"Word"} local Birck = workspace.Part Players.PlayerAdded:Connect(function(Player) Player.Chatted:Connect(function(ChatMessage) for _,Word in pairs(FindWords) do if (ChatMessage:lower():find(Word:lower())) then Brick.CanColide = false Brick.Transparency = 1 end end end) end)