Help with seat sounds

How do i make it so a seat plays a sound whenever the player sits in it?

If a player sits, it plays a sound

like smth like this:

local part = script.Parent
local seat = part:FindFirstChild("Seat")

local Sound = script.Parent:FindFirstChild("Sound")


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant ~= nil and seat.Occupant.Parent:FindFirstChild("Humanoid") then
		local plr = seat.Occupant.Parent-- idk do smth with the player if you want

		print(plr.Name)
		Sound:Play()
	end
end)

1 Like

waitforchild() is better on a starting up script like this.
nice script btw! I do this a bit different …

--local script in StarterGUI or StarterPlayer.StarterPlayerScripts

local rs=game:GetService("RunService")
local player=game:GetService("Players").LocalPlayer
local playerGui=player:WaitForChild("PlayerGui") -- stalling a bit
local char=player.Character or player.CharacterAdded:Wait()
local humanoid=char:WaitForChild("Humanoid")
local Sit = false

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	rs.Stepped:Wait() -- this is needed for it to fire as intended
	if (humanoid.Sit)==true and Sit==false then Sit=true
		if humanoid.SeatPart.Name=="Seat" then -- the name of the seat
		--	play the sound
		end
	else Sit = false
	end
end)

-- may a well use this for more

local db=true
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	rs.Stepped:Wait()

	if humanoid.FloorMaterial==Enum.Material.CrackedLava then
		if db then db=false task.wait(2)
			humanoid.Health=0 db=true
		end
	end
end)

-- could control what every seat name will do with this script and a few other things.

This has become a standard script I use in StarterGUI named signals this controls seats and step ons for me. Also a few other things related to that. That is why playerGUI is in the mix up top.

1 Like