Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this not change the part's attributes when a certain message is chatted?

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		if msg == ":open" then
			game.Part.Transparency = 1
			game.Part.CanCollide = false
		elseif msg == ":close" then
			game.Part.Transparency = 0
			game.Part.CanCollide = true
		end
	end)
end)

There is only one object called Part in the workspace.

1 comment

0

"Disconnected event because of exception" is the error I receive.

3 answers

✓ Accepted answer
game.Part

Part isn't a child of game. I think you mean

game.Workspace.Part

In Lua, you always go from broad to specific. You can't go directly from very broad to very specific, you must put the complete path to the object, starting at the broadest possible (game) and getting more and more specific until you find Part.

1 comment

0

Thank you very much, I'm surprised I didn't catch that.

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        if msg :find( ":Open":lower() ) then -- hi this is bob OH yea I forgot :open *script finds the executes*
            game.Workspace.Part.Transparency = 1
            game.WorkspacePart.CanCollide = false
        elseif msg:find( ":Close":lower() ) then
           game.Workspace.Part.Transparency = 0
           game.Workspace.Part.CanCollide = true
        end
    end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.