Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont the seat make the funcion clear?

so bassicly whenever is it i want it to make a sound and when i leave the seat its makes a sound but it doesnt work

local a = script.Parent.Unsits
local b = script.Parent.Sits
local c = script.Parent


	

if c.Occupant ~= nil then
		b:Play()
		
	end
	if c.Occupant == nil then
		a:Play()
	end

1 answer

✓ Accepted answer

Well, you're on the right track. However your mistake is that you're running this code as soon as the server starts, and it only runs once. To run only when a player sits in a seat we're going to want to run the :GetPropertyChangedSignal() method on the seat and listen for the Occupant property.

local Seat =  script.Parent

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	
end)

This code will run whenever somebody sits or leaves the specific seat.

Now of course we will want to check which of those it is, and play the sound depending on whether they sat down or left the seat.

local Seat =  script.Parent
local SoundOne = script.Parent:WaitForChild("Sits")
local SoundTwo = script.Parent:WaitForChild("Unsits")

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		SoundOne:Play()
	else
		SoundTwo:Play()
	end
end)

I hope this helped. You should take a look at this link to better understand the use of this method for future reference.

If I did help, then please mark my answer as accepted or reply to this answer if you need further help!

2 comments

0

The sounds wont play,but i do appreciate the answer thanks!

0

Oops! My bad! It does work in the roblox player but not in studio thanks!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.