Sending keydown event being pressed to a sailboat

I am quite new to scripting and have successfully managed to make functions with UIS (User Input Service). Now Since I am making a sailing simulator, and many boats are being cloned, I could not find a way to get a player’s keybinds to influence the settings of their own boat’s settings (mainsheet, etc).

This is the code I used to get the original functions with UIS.



local uis = game:GetService("UserInputService")



uis.InputBegan:Connect(function(input)
	
	
	if input.KeyCode == Enum.KeyCode.W then
		print("W key held")
		
	end
end)

uis.InputEnded:Connect(function(input)
	

	if input.KeyCode == Enum.KeyCode.W then
		print("W key released")

	end
end)


	

This local script was placed in StarterPlayerScripts.

Thanks,

CoolDanu.

You need to use remote events, if you want to get what the client pressed.

After that in the server script, it should listen to that remote event, check what player triggered the remote event, and check what boat is he in. After that change the settings.

Also I would recommend this video , how to use remote events, as they are really useful.

1 Like

Now I watched the video. At 4:29 he uses this code on line 3 in script of remote event:

rep.BrickOn.OnServerEvent:Connect(function(player)

Now in the function if you call for the parameter “player” will it return the player name or anything I can use that to check the player?

in an OnserverEvent there is always a parameter created it is known as who fired it when u fire an event and u want to have a parameter in it, it will be like this:

rep.BrickOn:FireServer(parameter)
then on the OnServerEvent it will be like this

rep.BrickOn.OnServerEvent:Connect(function(player, parameter)
so u shouldnt forgot to put the parameter for the player who fire the event

1 Like

Just to be sure I can use:

local name = game.Players.LocalPlayer.Name

(the var would be CoolDanu in my case)
and compare it to a value on the boat with the owner written on.

actually you cant use LocalPlayer in a script only on Local Script also if you are doing it in server event it wont work so if you are using it on a local script yea it will work

1 Like

this line was added just now to the local script above on my studio.

yea it will work -------------

1 Like

thanks for the help. will ask if i need.

1 Like

Ok my mistake i did not add that line to the local script. I added it to a script in the model. Is it possible to send parameters through a :fireserver event? like so?

rep.MainsheetOn:FireServer(name)

rep is replicated storage and name is the local variable for the player name that held W.

yes u can add paramter as much as you want but no need to send a parameter for the player it already send this parameter when the player fires it

1 Like

You do not actually have to write in ‘player’. The Remote Event will automatically pass the parametre. Just be sure to put it in the function to which you are connecting.

1 Like

So this is the script in the model. I’m activating it through the line in the above post with just the player parameter. Not getting any output through the print statement I made.

rep = game.ReplicatedStorage

rep.MainsheetOn.OnServerEvent:Connect(function(player)
	print(player)




end)

As I said, the Remote Event gives you the player as an Instance. To print out the player’s name, put player.Name in that ‘print’ function bracket.