After some recent drama i decided to go back to my Czechoslovak train simulator, so far I’m scripting a locomotive and I’m trying to make it so that when i press a certain key (H or B) a different sound is played according to the key pressed respectively. Here is the script I am using.
local Vehicle = script.Parent.Parent.VehicleSeat
Vehicle.Touched:Connect(function(sit)
local sound = Instance.new("Sound", game:GetService("ReplicatedStorage"))
sound.Parent = game.Workspace:WaitForChild("363").Horn
sound.Name = ("363Horn")
sound.SoundId = "rbxassetid://12272587082"
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.KeyCode == "H" then
sound:Play()
end
end)
local sound2 = Instance.new("Sound", game:GetService("ReplicatedStorage"))
sound2.Parent = game.Workspace:WaitForChild("363").Horn
sound2.Name = ("363Whistle")
sound2.SoundId = "rbxassetid://12272587025"
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.KeyCode == "H" then
sound:Play()
end
end)
end)
The code is supposed to detect when the player sits on the VehicleSeat and when they do they are able to play either a horn or whistle if they press H or B and when they get off they cant do so (obviously)? So far it hasn’t been working and I don’t know what else to do
This script is put inside a MeshPart called Horn, in which the sounds come from
Any suggestions?