Right then, I've got this drive system for a train that i've been working on. It all works fine and dandy. However, it ajust's things like the chuffing sounds for it through the local script, and as a consequence only the driver can hear it. In future i'll be adding things like particle effects as well. What i'm aiming to do is to make it so everyone can hear it and I've read up about remote events and functions but after about a week of confusing myself I've reached the point where i could do with a bit of guidance.
Anyways, here's the code:
wait(.5) vehicle = game.Workspace:FindFirstChild(script.Parent.Train.Value) mouse = game.Players.LocalPlayer:GetMouse() Chassis = vehicle.Chassis reghinge=Chassis.Regulator.HingeConstraint regvalue=Chassis.Regulator.Value revhinge=Chassis.Reverser.HingeConstraint revvalue=Chassis.Reverser.Value cutoffhinge=Chassis.Cutoff.HingeConstraint cutoffvalue=Chassis.Cutoff.Value airbrakehinge=Chassis.AirBrake.HingeConstraint airbrakevalue=Chassis.AirBrake.Value brakeseat=vehicle.Body.BrakeSeat powerseat=vehicle.Body.PowerSeat driveseat = vehicle.Body.Seat chuff=vehicle.Body.Chimney.Chuff function KeyPress(key) if key == "e" then if regvalue.Value < 20 then reghinge.TargetAngle=reghinge.TargetAngle-5 powerseat.Torque=powerseat.Torque+.07 regvalue.Value=regvalue.Value+1 chuff.Volume=chuff.Volume+0.03 end end if key == "q" then if regvalue.Value > 0 then reghinge.TargetAngle=reghinge.TargetAngle+5 powerseat.Torque=powerseat.Torque-.07 regvalue.Value=regvalue.Value-1 chuff.Volume=chuff.Volume-0.03 end end if key == "w" then if revvalue.Value < 1 then revhinge.TargetAngle=revhinge.TargetAngle+15 powerseat.Throttle=powerseat.Throttle+1 revvalue.Value=revvalue.Value+1 end end if key == "s" then if revvalue.Value > -1 then revhinge.TargetAngle=revhinge.TargetAngle-15 powerseat.Throttle=powerseat.Throttle-1 revvalue.Value=revvalue.Value-1 end end if key == "r" then if cutoffvalue.Value < 4 then cutoffhinge.TargetAngle=cutoffhinge.TargetAngle+87 powerseat.MaxSpeed=powerseat.MaxSpeed+9 cutoffvalue.Value=cutoffvalue.Value+1 end end if key == "f" then if cutoffvalue.Value > 0 then cutoffhinge.TargetAngle=cutoffhinge.TargetAngle-87 powerseat.MaxSpeed=powerseat.MaxSpeed-9 cutoffvalue.Value=cutoffvalue.Value-1 end end if key == "]" then if airbrakevalue.Value < 6 then airbrakehinge.TargetAngle=airbrakehinge.TargetAngle+30 brakeseat.Torque=brakeseat.Torque+.3 airbrakevalue.Value=airbrakevalue.Value+1 end end if key == "[" then if airbrakevalue.Value > 0 then airbrakehinge.TargetAngle=airbrakehinge.TargetAngle-30 brakeseat.Torque=brakeseat.Torque-.3 airbrakevalue.Value=airbrakevalue.Value-1 end end end function LeaveSeat(child) if child.Name == "SeatWeld" then script.Parent:Destroy() end end mouse.KeyDown:connect(KeyPress) script.Parent.Parent.Parent.ChildRemoved:connect(LeaveSeat)
Any help is very much appreciated!
I would use remote events (i only recently learned how to do this but it's quite useful), Insert a new remote event into ReplicatedStorage (so both Server and Local scripts can access it) Name the RemoteEvent what ever you want and go into your local script.
Under
if key == "WhichEverKeyYouWant"
put
game:GetService("ReplicatedStorage").EventNameHere:FireServer()
(you may need a new event for every key pressed if you want them to do different things) and then in your regualr script (Server Script) put
game:GetService("ReplicatedStorage").EventNameHere.OnServerEvent:Connect(function() ---Code here (sound effects or whatever) end)
you can repeat this process with multiple events as long as they all have seperate names sorry if this is more like a tutorial than "help" but i hope it works if i'm not giving you a good enough example i'd reccomend searching "Remote Events" on the Roblox API Reference