Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i can make a KeyDown script without a Local one? (Solved)

Asked by
fff054 51
5 years ago
Edited 5 years ago

On a Local Script:

player = game.Players.LocalPlayer:GetMouse()

player.KeyDown:connect(function(key)



if key == "r" then






        Instance.new("Part", game.Workspace)

    end


end)

But this does not help me because i want to all can see it.

I want to do it on a script to all can see it.

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Sadly, this is for a keyboard key input. But, maybe it'll help.

  1. Add a RemoteEvent to game.ReplicatedStorage
  2. Name the event 'KeyPressed'
  3. Go to StarterPlayer > StarterPlayerScripts
  4. Right-click StarterPlayerScripts
  5. Hover 'Insert Object'
  6. Click 'Local Script'
  7. (Code): Type:
game:GetService('UserInputService').InputBegan:Connect(function(input, processed)
    if input.KeyCode == Enum.KeyCode.E then
        processed = true
        game.ReplicatedStorage.KeyPressed:FireAllClients()
    end
end)
  1. Add a script (Server script) to game.ServerScriptService
  2. Enter the script and type: (code):
game.ReplicatedStorage.KeyPressed.OnClientEvent:Connect(function()
    local part = Instance.new('Part', workspace)
end)
0
You need to call the server on the client (and you can't fire all clients directly on the client anyways) and use OnServerEvent on the server. hiimgoodpack 2009 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To detect for a keyboard key press you could use this:

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then
        print("R was pressed")
       Instance.new("Part", game.Workspace)
    end
end

game:GetService("UserInputService").InputBegan:Connect(onKeyPress)

Sorry for the poor indentation of this code.

Hope this helps,

Tweakified

0
Tweakified, Thanks for your script, but that was not the script that i was searching for. I want to when i press a key a part appears and all can see it. fff054 51 — 5y
0
Oh sorry. I forgot about the server-client filter :/ Use remote events then. Tweakified 117 — 5y

Answer this question