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

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

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.

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!

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