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

How can I make (multiple) invisible blocks visible when leaving a chair?

Asked by 6 years ago

I know how to turn the blocks invisible upon sitting in a specific chair, however I have no idea how to make the blocks visible again upon exiting the seat. So the question is, how do I do that? Yes I'm new.

0
Can you include your current code? User#5423 17 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

Hey mainliner,

I believe your question is as to how you'd go about detecting if the Character is getting up rather then sitting, well the answer to this is quiet simple. Oh, btw if that's not your question and if it's as to how you'd go about making all the parts visible after making them invisible then, all you need to do is reverse what you did previously. Anyway, I'll be going over the first thought of mine as to how you'd go about detecting if the player has sat on the seat or if the player is getting up.

All you need is the seat.Changed event with the paramater of val, then check if val is "Occupant" and if it is then check if the seat has an occupant or not. If it has an Occupant, then you simply need to make all the parts transparent and if it doesn't have an Occupant, then you simply just do the opposite of that, which would be to make them opaque. Below, I'll show you some simple code on how you can go about detecting if the player sat on it or if the player is leaving it.

local part = script.Parent; -- The seat.

function manage_actions(val) -- The function that will detect if the part's properties have changed.
    if val == "Occupant" then -- Checks if it was the Occupant property. This tells us that either someone is sitting or getting up.
        if part.Occupant then -- Checks if the Seat has an occupant. This means that somebody has just sat on it.
            print("Sitting.");
        else -- If hte part doesn't have an Occupant that means that somebody has just left it...
            print("Getting up.");
        end
    end
end

part.Changed:Connect(manage_actions); -- Connecting the function to the event so it's activated.

Well, I hope that helped you to deepen your knowledge about how to detect if somebody is sitting or if somebody is getting up. Have a wonderful day.

~~ KingLoneCat

Ad

Answer this question