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

How do you change the transparency of an object when "hello" is said?

I'm having difficulties changing an object's transparency to opaque when hello is said. I tried using EpicMetableMoment's script, when hello was said, it would change from white to black. I tried to change it to change the transparency of an object but I couldn't get it to work. Here is the code.

-- If true, make part visible	 
local players = game:GetService("Players")

local part = workspace:WaitForChild("Transparency")
local isTransparent = true --// our toggling variable 


local function togglePartColor()
    if isTransparent then --// check if transparent
        isTransparent = false --// set to false since we are making opaque
        part.Transparency = 0 --// change to opaque
    elseif not isTransparent then --// check if transparent
        isTransparent = true --// set to true since we are making Transparent
        part.Transparency = 1 --// set part transparency to transparent
    end
end

local function checkForCommand(message)
    local command = message:lower() --// make message lowercase

    if command == "hello" then --// check if this is our command
        togglePartColor() --// if its the command then toggle part's color
    end
end

local function playerAdded(player)
    player.Chatted:Connect(checkForCommand) --// connect chat event
end

players.PlayerAdded:Connect(playerAdded) --// connect player added so we can get reference to players who join

I'm very new to Roblox Lua so please don't get mad if I'm doing this completely wrong. Thanks for any help I get!

1 answer

✓ Accepted answer

I believe this issue is you haven't defined the part to be anything, and are misunderstanding the built in function "WaitForChild"

to fix this we are going to assume that your part is called part, and it is not in a model

-- If true, make part visible   
	local players = game:GetService("Players")
	 
	local part = game.workspace.part
	local isTransparent = true --// our toggling variable
 
	 
	local function togglePartColor()
	    if isTransparent then --// check if transparent
	        isTransparent = false --// set to false since we are making opaque
	        part.Transparency = 0 --// change to opaque
	    elseif not isTransparent then --// check if transparent
	        isTransparent = true --// set to true since we are making Transparent
	        part.Transparency = 1 --// set part transparency to transparent
	    end
	end
	 
	local function checkForCommand(message)
	    local command = message:lower() --// make message lowercase
	 
	    if command == "hello" then --// check if this is our command
	        togglePartColor() --// if its the command then toggle part's color
	    end
	end
	 
	local function playerAdded(player)
	    player.Chatted:Connect(checkForCommand) --// connect chat event
	end
 
	players.PlayerAdded:Connect(playerAdded) --// connect player added so we can get reference to players who join

If this helps don't forget to mark as answer.

1 comment

0

Great, thank you!

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