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

How do I make this tool change transparency when I press a specific key?

Basically I want a tool's handle to have it's transparency gradually fade in and out when I press 'F', and uh...mine isn't doing that, so here's what I've got so far.

brick = game.StarterPack.KeyPressing.Handle


local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)

	if input.UserInputType == Enum.UserInputType.Keyboard then

		if input.KeyCode == Enum.KeyCode.F == true then
			
			if brick.Transparency == 0 then do
			
			brick.Transparency +=.1
			
			wait (.5)
			
				repeat until brick.Transparency == 1
				
				end
		
			elseif brick.Transparency == 1 then do
	
			brick.Transparency -= .1
	
			wait(.5)
	
				repeat until brick.Transparency == 0
			
		end
end			

1 answer

✓ Accepted answer

The structure of the repeat until loop is incorrect, on lines 12-18 and 22-28. It should look something like this (starting from line 10):

if input.KeyCode == Enum.KeyCode.F then
	if brick.Transparency == 0 then
		repeat
			brick.Transparency = brick.Transparency + 0.1
			wait(0.5)
		until brick.Transparency >= 1
	elseif brick.Transparency == 1 then
		repeat
			brick.Transparency = brick.Transparency - 0.1
			wait(0.5)
		until brick.Transparency <= 0
	end
end

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