Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script not changing my bricks properties?

Asked by 4 years ago

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
0
is there any error? guest_20I8 266 — 4y
0
Is this code your own? Ziffixture 6913 — 4y
0
Is it that sloppy? ^ rylie2377 39 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
Ad

Answer this question