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?
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?
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
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
end
end)
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)
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Sorry for the lack of detail, but I only wanted the seat.occupant but thanks! I dont know which answer to mark as answer
It wont let me answer .-.