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 can make a KeyDown script without a Local one? (Solved)

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

✓ Accepted answer

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)

1 comment

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.

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

2 comments

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.

0

Oh sorry. I forgot about the server-client filter :/ Use remote events then.

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