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.
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.
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
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
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.
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.
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.