I was wondering if i can send different information through a RemoteEvent, Its hard to explain so ill just show through script.
Client Script
--Client --J local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputServer = game:GetService("UserInputService") local plr = Players.LocalPlayer local event = ReplicatedStorage:WaitForChild("event") UserInputServer.InputBegan:Connect(function(input, IsTyping) if IsTyping then return elseif input.KeyCode == Enum.KeyCode.J then local J = "J" event:FireServer(J) print("Fired Server") end end)
Client Script
--Client --K local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputServer = game:GetService("UserInputService") local plr = Players.LocalPlayer local event = ReplicatedStorage:WaitForChild("event") UserInputServer.InputBegan:Connect(function(input, IsTyping) if IsTyping then return elseif input.KeyCode == Enum.KeyCode.K then local K = "K" event:FireServer(K) print("Fired Server") end end)
Server Script
--Server local ReplicatedStorage = game:GetService("ReplicatedStorage") local event = ReplicatedStorage:WaitForChild("event") event.OnServerEvent:Connect(function(J, K) if J then print("J was clicked") elseif K then print("K was clicked") end end)
When I play the game and Click K It just ends up saying " J was clicked" Although I clicked K. How would I do this? Is it even possible?
First of all, you only put in one parameter, which is a string called "K" or "J". You don't have to create another parameter for it. Also what Arson said, FireServer command on default has a player parameter.
Your code would be this:
--Server local ReplicatedStorage = game:GetService("ReplicatedStorage") local event = ReplicatedStorage:WaitForChild("event") --parameters player and key event.OnServerEvent:Connect(function(player, key) if key == "J" then print("J was clicked") elseif key == "K" then print("K was clicked") end end)
In short, you just needed to add the parameter of the player and only need one string parameter.
It is because when a remote event is sent from a client to the server, one of the parameters is the player who sent the remote event. The first parameter is always the player who sent the remote event if you are sending it from client to server. The fix would be this:
--Server local ReplicatedStorage = game:GetService("ReplicatedStorage") local event = ReplicatedStorage:WaitForChild("event") --Rather than check which key you pressed, you just checked if the parameter exist. --This is the revised scrip. event.OnServerEvent:Connect(function(player, keyPressed) if keyPressed == "J" then print("J was pressed!") elseif keyPressed == "K" then print("K was pressed") end end)