I'm trying to modify this script that gives you the GUI when you sit on a seat, and when you leave the seat, the GUI disappears unless you sit on it again; which, of course, comes back. In the car seat, I have the script and an audio inside of it called "EngineIdle" which is unneeded for me. But when I remove this unnecessary audio, the seat you get on with GUI stays with you and doesn't disappear as I intend to be when you leave the driver's seat.

Here's the script;

local seat = script.Parent
local car = seat.Parent
local originalGUI = script:WaitForChild("DriveGUI")
originalGUI:WaitForChild("Car").Value = seat.Parent

seat.ChildAdded:connect(function( newChild )	
	if newChild:IsA("Weld") then
		newChild.C0 = CFrame.new(0,(seat.Size.y/2 + 1.5),0)
		newChild.C1 = CFrame.new(0, 1.0, 0)
		if newChild.Part1.Name == "HumanoidRootPart" then
			local player = game.Players:GetPlayerFromCharacter(newChild.Part1.Parent)
			if (player) then
				if (not player.PlayerGui:FindFirstChild("DriveGUI")) then
					originalGUI:Clone().Parent = player.PlayerGui
				else
					-- In case a player already has a GUI (can be caused by various bugs), set this car as subject.
					player.PlayerGui.DriveGUI.Car.Value = seat.Parent 
				end
			end
		end
	end
end)

seat.ChildRemoved:connect(function( oldChild )
	if oldChild:IsA("Weld") then
		if oldChild.Part1.Name == "HumanoidRootPart" then
			local player = game.Players:GetPlayerFromCharacter(oldChild.Part1.Parent)
			if player then
				seat.EngineIdle:Stop()
				if (player.PlayerGui:findFirstChild("DriveGUI")) then
					player.PlayerGui.DriveGUI.Car.Value = nil
					wait(0.1)
					player.PlayerGui.DriveGUI:Destroy()
					-- Stop the car
					car.ComboSuspension.W1.TopParamB = 0
					car.ComboSuspension.W2.TopParamB = 0
					car.PoweredSuspension.W1.TopParamB = 0
					car.PoweredSuspension.W2.TopParamB = 0
				end
			end
		end
	end
end)

This is the whole script

seat.ChildRemoved:connect(function( oldChild )
	if oldChild:IsA("Weld") then
		if oldChild.Part1.Name == "HumanoidRootPart" then
			local player = game.Players:GetPlayerFromCharacter(oldChild.Part1.Parent)
			if player then
				seat.EngineIdle:Stop()
				if (player.PlayerGui:findFirstChild("DriveGUI")) then
					player.PlayerGui.DriveGUI.Car.Value = nil
					wait(0.1)
					player.PlayerGui.DriveGUI:Destroy()
					-- Stop the car
					car.ComboSuspension.W1.TopParamB = 0
					car.ComboSuspension.W2.TopParamB = 0
					car.PoweredSuspension.W1.TopParamB = 0
					car.PoweredSuspension.W2.TopParamB = 0
				end
			end
		end
	end
end)

You may notice that "seat.EngineIdle:Stop()" exists which is the unneeded audio in my seat that ruins the GUI interface when you remove it. How do I make it so when you get on the seat it gives you the GUI interface, but when you leave it, it disappears without having "EngineIdle" audio?

3 comments

0

So you could honestly set the audios volume to 0, that's the simplest way around this.

0

Saying that that is harder to stopping the audio?

0

destroy() i kinda broken nowadays.