This is not a request, but I was wondering where would I add a KeyDown function in this function, I am really not sure and would need some help.
Basically when the key, example "e" is pressed it would FireServer()
function onTouched(hit) local Humanoid = hit.Parent:FindFirstChild("Humanoid") if not Humanoid then return; end if not script.Parent:WaitForChild("ButtonEvent") then script.Parent:Destroy() return; end script.Parent.ButtonEvent:FireServer() end script.Parent.Touched:connect(debounce(onTouched))
Since KeyDown
is a event of mouse
you could access player
from hit
by using the :GetPlayerFromCharacter
.
function onTouched(hit) local Humanoid = hit.Parent:FindFirstChild("Humanoid") if not Humanoid then return; end if not script.Parent:WaitForChild("ButtonEvent") then script.Parent:Destroy() return; end local pl = game.Players:GetPlayerFromCharacter(hit.Parent) local mouse = pl:GetMouse() mouse.KeyDown:connect(function(key) if key == "e" then script.Parent.ButtonEvent:FireServer() end end) end script.Parent.Touched:connect(debounce(onTouched))