Dear Friends,
I’m a beginner of the Car modelling, and scripting. and need of a some comments to help me out making of ‘DMC DeLorean’
Now, I’m planning to make this work like these steps.
No. 1: Sit the ‘Vehicleseat’ and startup the engine by holding the ‘E’ key. (Enabling the ‘CarScript’)
No. 2: When you hold the ‘E’ key, anytime between 2~60 seconds, The Engine will start. (with playing ‘BlinkSound’, ‘CrankSound’, and play ‘startSound’ when its started)
No. 3: If you press the ‘X’ key then, the engine will stop. (Disabling the ‘CarScript’)
Now, the issue is to code some kind of ‘UserInputService’ into the VehicleSeat
had been coded the ‘LocalScript’ with it. but it doesn’t worked out.
even tried with ‘Script’ but it won’t worked as well.
Have been looked everything on Developer Forum varying topics(like to boost, lights)
but doesn’t worked out as hoped.
would be looking forward to have some helps from y’all kind people. it would be appreciated.
UserInputService is always used in LocalScripts, but LocalScripts can only run where the client is replicated. You placed your LocalScript inside the vehicle, which is in Workspace, and LocalScripts don’t run directly in Workspace (unless they’re inside the player’s character).
a few places where local scripts will run are: StarterPlayerScripts, StarterCharacterScripts, StarterGui
Whenever a player presses the keys you just need to fire a remote event (Which should be parented in ReplicatedStorage somewhere), and you can have a server script manage the input. If you dont fire the remote event and instead handle everything inside of the local script, then only the playerw ho is driving will see the vehicle move and no other players will. There are many many guides online explaining client-server relations (example tutorial that explains client-server stuff)
A RemoteEvent lets a LocalScript tell the server to do something, like play a sound, so all players can hear it. You’ll need to set up two scripts: one LocalScript to get the input and fire the RemoteEvent, and one ServerScript to be triggered by the RemoteEvent to play the sound for everyone. It’s a bit complicated, but not really, and it’s something you’ll end up using all the time, so you might as well learn it now.
That localscript I see does something when you press the E so there is something like this in it..
local replicatedStorage = game:GetService("ReplicatedStorage")
-- you'll add this.. I named the remotevent PlayVehicleSound
local playVehicleSound = replicatedStorage:WaitForChild("PlayVehicleSound")
-- this should be in the script someplace
if input.KeyCode == Enum.KeyCode.E then
-- right here you fire the remote you set up for this..
playVehicleSound:FireServer(vehicle)
end
If that was a stand alone local
local userInput = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local playVehicleSound = replicatedStorage:WaitForChild("PlayVehicleSound")
local vehicle = workspace:WaitForChild("YourVehicle")
--and you need the path to the seat with that now or in the server script
userInput.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.E then
playVehicleSound:FireServer(vehicle)
end
end)
From here it’s gets pretty simple.. in the ServerScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local playVehicleSound = replicatedStorage:WaitForChild("PlayVehicleSound")
playVehicleSound.OnServerEvent:Connect(function(player, vehicle)
local crank = vehicle:WaitForChild("CrackSound")
local start = vehicle:WaitForChild("StartSound")
crank:Play()
task.wait(1)
start:Play()
end)
If you can stumble a bit here and post your scripts, we can definitely help fix it up.
I know this sounds overwhelming.. but it’s not once you understand it.
This is actually pfft, and you’ll get it if your try a bit.