Still have questions? Join our Discord server and get real time help.
0

# When making a script how would you know when a player is sitting? *specific title*

Example: Imagine you wanted to make a seat that gives 1 leader stat per second while you sit on it

How would the script detect if the player is sitting on it?

0
Sparks 534
14 days ago
Edited 14 days ago

I am making a lot of assumptions here due to the vague details, but something you can use is GetPropertyChangedSignal with the Seat.Occupant property

Assuming there is already a leaderstat folder and a "Seconds" IntValue inside of it:

-- Script should be inside the seat
local Seat = script.Parent
local Players = game:GetService("Players")

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
--Get seat occupant
local humanoid = Seat.Occupant

--Check to make sure seat is not empty
if humanoid == nil then return end

--Get the player sitting in the seat
local occupant = Players:GetPlayerFromCharacter(humanoid.Parent)

--Get that player's seconds from the leaderboard

--Increment their seconds on the leaderboard by 1 while sitting
while Seat.Occupant == humanoid do wait(1)
Seconds.Value += 1
end
end)


0
Sorry for the lack of detail, but I only wanted the seat.occupant but thanks! I dont know which answer to mark as answer Script_Summary 13 — 14d
0
It wont let me answer .-. Script_Summary 13 — 14d
0

while true do
if script.Parent.Occupant ~= nil then
script.Parent.Color = Color3.fromRGB(255, 0, 0)
elseif script.Parent.Occupant == nil then
script.Parent.Color = Color3.fromRGB(27, 42, 53)
end
wait()
end


Basically what this script does, if you add it to a Seat, when the seat is being used by someone the seat becomes red, and when it's not, it becomes black (assuming the original color of the seat is black). The code-lines 3 and 5 can be replaced with anything actually, so yeah, I guess there you have it.