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

i want to know the funtion to detect a key from keyboard how do i do it?

im new to scripting and in lua to detect if an keyboard key what been touched

example i want to do a function that makes the baseplate tranparency = 0.5

function() BaseplateTranparency if io.read() = e do game.Workspace.Baseplate.Transparency = 0.5 if io.read() = q do game.Workspace.Baseplate.Transparency = 1 end

2 answers

✓ Accepted answer

Try creating a new localscript and add it in StarterPlayerScripts. Also add a script into ServerScriptService. Create a RemoteEvent and put it somewhere, example ReplicatedStorage.

Put this code in localscript:

local player = game.Players.LocalPlayer --get player
local mouse = player:GetMouse() -- get mouse
local remote = game.ReplicatedStorage.RemoteEvent --your event path here

mouse.KeyDown:Connect(function(key) 
	if key == "g" then --if key is g then
		remote:FireServer() --fire the server
	end
end)

Put this into script:

local event = game.ReplicatedStorage.RemoteEvent --your event here
event.OnServerEvent:connect(function(player) --when even is fired this function will start
--your code here
workspace.Baseplate.Transparency = 1
end)

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