Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont the seat make the funcion clear?

Asked by 3 years ago

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

01local a = script.Parent.Unsits
02local b = script.Parent.Sits
03local c = script.Parent
04 
05 
06 
07 
08if c.Occupant ~= nil then
09        b:Play()
10 
11    end
12    if c.Occupant == nil then
13        a:Play()
14    end

1 answer

Log in to vote
1
Answered by
awfulszn 394 Moderation Voter
3 years ago

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.

1local Seat =  script.Parent
2 
3Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
4 
5end)

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.

01local Seat =  script.Parent
02local SoundOne = script.Parent:WaitForChild("Sits")
03local SoundTwo = script.Parent:WaitForChild("Unsits")
04 
05Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
06    if Seat.Occupant ~= nil then
07        SoundOne:Play()
08    else
09        SoundTwo:Play()
10    end
11end)

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!

0
The sounds wont play,but i do appreciate the answer thanks! Yodadthin 2 — 3y
0
Oops! My bad! It does work in the roblox player but not in studio thanks!!! Yodadthin 2 — 3y
Ad

Answer this question