Hello, i am currently trying to make a thruster for a rocket and when the player in the vehicle seat presses F, the rocket moves and it makes the fire particles at the thruster visible. I did successfully made it but the particles only show up for the person controlling the rocket.
I need so when a player sits on a vehicle seat and presses F, particles will be visible for everyone and not just for the person sitting on the vehicle seat.
I tried looking for solutions in the developer forums but i can’t seem to find any that fits my situation.
Here’s a local script code that will be duplicated inside the player’s character.
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local hold = false
humanoid.Seated:Connect(function(isSeated, seat)
if isSeated then
if seat then
local Player = game.Players.LocalPlayer
mouse.KeyDown:connect(function(key)
if key == "f" then
print("Down E")
workspace.VehicleSeat.Pat.EffectCentral.Enabled = true
workspace.VehicleSeat.Pat.EffectInside.Enabled = true
workspace.VehicleSeat.Pat.EffectOuter.Enabled = true
workspace.VehicleSeat.Pat.PointLight.Enabled = true
workspace.VehicleSeat.BodyThrust.Force = workspace.VehicleSeat.BodyThrust.Force + Vector3.new(0,35000,0)
end
end)
mouse.KeyUp:connect(function(key)
if key == "f" then
print("Up E")
hold = false
workspace.VehicleSeat.Pat.PointLight.Enabled = false
workspace.VehicleSeat.BodyThrust.Force = Vector3.new(0,0,0)
workspace.VehicleSeat.Pat.EffectCentral.Enabled = false
workspace.VehicleSeat.Pat.EffectInside.Enabled = false
workspace.VehicleSeat.Pat.EffectOuter.Enabled = false
end
end)
end
else
script:remove()
end
end)
And here’s the server script so when a player sits on a vehicle seat, the local script gets duplicated into the player’s character.
function powers()
if script.Parent.Occupant~= nil then
local Anyone = script.Parent.Occupant
local player = game.Players:GetPlayerFromCharacter(Anyone.Parent)
if player ~= nil then
if Anyone.Parent:findFirstChild("LocalScript") == nil then
local Load = script.Parent.Key.LocalScript:Clone()
Load.Parent = player.Character
Load.Disabled = false
Load.CarValue.Value = script.Parent.Parent
end
end
end
end
script.Parent.Changed:Connect(powers)
If you know any solutions then please reply. Thank you!
The reason it doesn’t appear for others is because, this is a local script, which will only run for the local player.
A solution to fix this, is using a server script instead. (Obviously.)
How to get the player, you may ask? That’s simple, we’ll make a parameter for the .Seated function which will get the humanoid player:
humanoid.Seated:Connect(function(Player, isSeated, seat)
print(Player) -- The parameter player will be the player who ran the event. (humanoid.Seated)
end)
There we go, now try getting the player that way using a serverscript.
Thanks for the reply! I’m quite new in scripting so I don’t know what humanoid is supposed to be in the 1st line of the script. I copied the code to a script and put it inside the seat but nothing was printed so i assume that it’s because the script doesn’t know what humanoid is. Am i doing something wrong?
I don’t think your input works either, you never informed what “mouse” is in the script, it’ll only give you nil as you have nothing, yet.
And I don’t think mouse is what you’re looking for, assuming you want a keyboard since you have .KeyCode, here’s how to do it:
local UserInputService = game:GetService("UserInputService") --This will load in the service.
UserInputService.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == "f" then
print("pressed f")
end
end
Hey, i’m having trouble trying to make the server sided script detect a player sitting on the seat. This is the line that i’m confused about. I tried using a local script to connect with the server script but it also didn’t work.
You can use remote events to replicate stuff from client to server, and for the line, it means when the humanoid (a variable for .Character.Humanoid) state’s is sitting it will run the function with three parameters, player, isseated and seat. (First arg is always automatically player)
But can a server sided script detect a humanoid? Like at humanoid.Seated. As far as i know i don’t think it can check for every individual players. So is that line is supposed to be a local script? because it can easily be done. and if so, how will i connect it with the server sided script?
I don’t think server side can detect humanoid this way, but you can make the local script replicate the effect making for the thruster since you want it to be global, to the server with a remote event
Hey, i managed to connect the local script to server script by using remote events. It works but for some reason it only shows for the driver again.
Here’s a local script placed inside the player’s character when they enter the seat
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService") --This will load in the service.
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
local dremoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTesta")
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.F then
print("Down F")
remoteEvent:FireServer()
workspace.VehicleSeats.Pat.EffectCentral.Enabled = true
workspace.VehicleSeats.Pat.EffectInside.Enabled = true
workspace.VehicleSeats.Pat.EffectOuter.Enabled = true
workspace.VehicleSeats.Pat.PointLight.Enabled = true
workspace.VehicleSeats.Pata.EffectCentral.Enabled = true
workspace.VehicleSeats.Pata.EffectInside.Enabled = true
workspace.VehicleSeats.Pata.EffectOuter.Enabled = true
workspace.VehicleSeats.Pata.PointLight.Enabled = true
workspace.VehicleSeats.dock.BodyThrust.Force = workspace.VehicleSeats.dock.BodyThrust.Force + Vector3.new(2200000,0,0)
end
end)
UserInputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.F then
print("Up F")
dremoteEvent:FireServer()
workspace.VehicleSeats.Pat.PointLight.Enabled = false
workspace.VehicleSeats.dock.BodyThrust.Force = Vector3.new(0,0,0)
workspace.VehicleSeats.Pat.EffectCentral.Enabled = false
workspace.VehicleSeats.Pat.EffectInside.Enabled = false
workspace.VehicleSeats.Pat.EffectOuter.Enabled = false
workspace.VehicleSeats.Pata.EffectCentral.Enabled = false
workspace.VehicleSeats.Pata.EffectInside.Enabled = false
workspace.VehicleSeats.Pata.EffectOuter.Enabled = false
workspace.VehicleSeats.Pata.PointLight.Enabled = false
end
end)
Here’s the script inside the rocket.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
-- Create a new part
local function onCreatePart(player)
print(player.Name .. " fired the remote event")
local newPart = script.EffectCentral:Clone()
local newPart1 = script.EffectOuter:Clone()
local newPart2 = script.EffectInside:Clone()
newPart.Parent = script.Parent.Pata
newPart1.Parent = script.Parent.Pata
newPart2.Parent = script.Parent.Pata
end
-- Call "onCreatePart()" when the client fires the remote event
remoteEvent.OnServerEvent:Connect(onCreatePart)
The particles did get cloned and it was coded inside a server script. I have no idea why it only shows for the driver.