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

How would i make a script so when i sit in a seat a monitor screen changes to neon material?

Asked by
Tnipo 10
4 years ago

So i made a monitor and i have a chair but i want the monitor screen to light up so change the material to neon. So it shows like you would be using the computer. I really have not experimented changing/manipulating parts with scripts before.

3 answers

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago
local Seat = script.Parent -- The seat
local Monitor = PathToMonitor -- Change to where your monitor is

Seat:GetPropertyChangedSignal("Occupant"):Connect(function() -- Run the below code when the Occupant changes
    if Seat.Occupant then -- Checks if someone is sitting in the Seat
        Monitor.Material = Enum.Material.Neon -- If someone is sitting in the seat
    else
        Monitor.Material = Enum.Material.Plastic -- If someone is not sitting in the seat
    end
end)

Don't forget to mark my answer as the solution and upvote it if it solved your problem :)

0
*Chooses the answer that was newer than mine* PoppyandNeivaarecute 134 — 4y
0
Your code doesn't work tho, OnChanged isn't an event and you don't even know how to check if the Occupant is a Humanoid Filipalla 504 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Assuming it doesn't matter who is in the seat, this could work: (put script in seat)

local monitor = ??? --Make this the location of the monitor
script.Parent.Occupant.OnChanged:connect(function()
    if script.Parent.Occupant == humanoid then 
        monitor.Material = Enum.Material.Neon
    else
        monitor.Material = Enum.Material.Plastic --Change this to the default material
    end
end
0
You can't do that, it better to use monitor = game.Parent.Monitor Block_manvn 395 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hello Tnipo, I have found a solution to your problem.

place the script inside the seat.

Good Luck!

--script is inside seat

--get reference to seat
local Seat = script.Parent

-- get reference to "Occupant" property of seat
local Occupant = Seat.Occupant

--get reference to screen (your path may differ)
local Screen = script.Parent.Parent.Parent.Monitor.Screen

--create material variables
local Neon = Enum.Material.Neon
local SmoothPlastic = Enum.Material.SmoothPlastic

--create function to handle the event
local function toNeon()
    if Seat.Occupant then
        Screen.Material = Neon
    else
    Screen.Material =SmoothPlastic
    end
end

--fires event
Seat:GetPropertyChangedSignal("Occupant"):Connect(toNeon)
-- the above line detects when the "Occupant" property of the seat is changed, and then executes the function toNeon()

Answer this question