So, I’m trying to make a car and I’m wondering.
How can I not have to use remote events or how can I use less?
For example: A and D have 2 different events
can I cut it down to one?
So, I’m trying to make a car and I’m wondering.
How can I not have to use remote events or how can I use less?
For example: A and D have 2 different events
can I cut it down to one?
You trying to do server or client? Example.
--- This is an Example on how they work
---Client to Server
local RE = --- Location of RemoteEvent
local Tool = --- Location of tool
Tool.Equipped:Connect(function()
RE:FireServer()
end)
--- Script on Server Side
local RE = --- Location of RemoteEvent
RE.OnServerEvent:Connect(function()
--- Script goes here
end)
Good question.
The way you can do it is by passing in parameters.
Sorry I am not able to explain more I have run out of time however someone else might be able to explain.
I guess you could use RemoteFunctions for two-way communication.
If you read the post further than the title, you would see that the OP is actually asking how to reduce their RemoteEvent usage, not how to use them.
oh, Im a idiot Did not see that
Okay sorry about that I am back. Since no one has explained I will do so.
What is good about a local event is that you can pass your own arguments through too.
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
createPartEvent:FireServer(BrickColor.Green(), Vector3.new(10, 20, 0))--Look here parameters are passed through
-- ========================================
-- Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
createPartEvent.Name = "CreatePartEvent"
local function onCreatePartFired(player, color, position) -- Look here. The colour and position is passed through
print(player.Name, "wants to create a part")
local newPart = Instance.new("Part")
newPart.BrickColor = color
newPart.Position = position
newPart.Parent = game.Workspace
end
createPartEvent.OnServerEvent:Connect(onCreatePartFired)
In this example you can see that a colour and a position is passed through the event.
In your case you just have to pass in the inputs from the player directly to the server and let the server sort it out.
In theory you could literally just have one remote event for an entire game that takes in all events and pass through a bunch of arguments to see what the server will do(although it is a bad idea).
You have to add the player parameter in the OnServerEvent
function, like this:
--- Script on Server Side
local RE = --- Location of RemoteEvent
RE.OnServerEvent:Connect(function(player)
--- Script goes here
end)
There is actually a great tutorial by @sleitnick on his Youtube channel.
Check it out: Roblox: Car Rig Tutorial (Part 1 - Setup) - YouTube
It contains the scripting and all, no remote events and also includes rigging the car.
Sorry if this isn’t what you’re looking for, quite new to the DevForum.
Hello lukethebestpug!
I assume you are looking to centralize your remote events into just a singular one. Doing this would require an argument field which tells you what the player is trying to change.
I have provided some code as an example which should allow you to expand the list.
local remoteevent = script.Parent.RemoteEvent
--
remoteevent.OnServerInvoke:Connect(function(player,argument,...)
assert(player == player,"Player who fired the remote event is not the player who is driving the vehicle!") --change this for a server sanity check
--
if argument == "lights" then
local parameters = {...}
print(parameters[1],parameters[2])) --true,"testprint"
elseif argument == "wheels" then
local parameters = {...}
print(parameters[1],parameters[2])) --false,"testprint2"
end
end)
The client code can be found below. This would be an example on what you want to do.
local remoteevent = script.Parent.RemoteEvent
--
remoteevent:FireServer("lights",true,"testprint")
remoteevent:FireServer("wheels",false,"testprint2")