Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by 14 days ago

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?

2 answers

Log in to vote
Answered by
Sparks 534 Moderation Voter
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")

    --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
    local seconds = occupant.leaderstats.Seconds    

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

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
It wont let me answer .-. Script_Summary 13 — 14d
Log in to vote
Answered by 14 days ago

Well, this script may help you:

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)

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.

Answer this question