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

Can someone tell me what wrong with this light keybind localscript?

local light = script.Parent.Parent.Parent.Body.Li
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
	if key == "z" then
		light.Lamp.Lighto.Light.Visible = true
	else
		light.Lamp.Lighto.Light.Visible = false
	end
end)
game.Players.LocalPlayer:GetMouse().KeyUp:connect(function(key)
	if key == "z" then
		light.Lamp.Lighto.Light.Visible = true
	else
		light.Lamp.Lighto.Light.Visible = false
	end
end)

i have a picture to https://gyazo.com/3e6a07a3f427c5ab97c84b1848cbcd94 and https://gyazo.com/637b682a109629f07e12158c6786a5ea

1 comment

0

Mouse.KeyDown is deprecated, use UserInputServer.InputBegan instead

2 answers

Mouse.KeyDown is deprecated, use UserInputService. It is much better it can be found on the wiki.

1 comment

0

like this? V

like this?

local light = script.Parent.Parent.Parent.Body.Li
game.Players.LocalPayer:UserInputServer().InputBegan:connect(function(key)
    if key == "z" then
        light.Lamp.Lighto.Light.Visible = true
    else
        light.Lamp.Lighto.Light.Visible = false
    end
end)
game.Players.LocalPlayer:UserInputServer().InputBegan:connect(function(key)
    if key == "z" then
        light.Lamp.Lighto.Light.Visible = true
    else
        light.Lamp.Lighto.Light.Visible = false
    end
end)

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