Tweening Transparency on a touch

Hello Roblox Devs!

I am trying to make it so when the player is not inside a building, the interior of the building is not visible

But when the player IS Inside the building, the inside of the building is!

Here is my tween code for transparency:

local Info = TweenInfo.new(1)
local TweenIn = game:GetService("TweenService"):Create(script.Parent,Info,{Transparency=0})
local TweenOut = game:GetService("TweenService"):Create(script.Parent,Info,{Transparency=1})

TweenOut:Play() -- Makes The Inside Of The Building Visible

TweenIn:Play() -- Makes The Inside Of The Building Not Visible

I want it to look a little something like this:

1 Like

Store the stuff you want invisible in a separate folder.
Note, if you have models, check for models, then run another loop to make the stuff inside the model invisible too.

Also just edit the tween script in between it like:

local invis = game.Workspace.Path_Invisible_Folder

for i, v in pairs(invis:GetChildren()) do
if v:IsA(“BasePart”) then
local Info = TweenInfo.new(1)
local TweenIn = game:GetService("TweenService"):Create(v,Info,{Transparency=0})
local TweenOut = game:GetService("TweenService"):Create(v,Info,{Transparency=1})

TweenOut:Play()

--TweenIn:Play() for when you exit build mode.
end
end

Place this in like the script that enters you into build mode.

2 Likes

What error are you getting? Nothing glaringly wrong with your code.

1 Like

So something like this?

-- Local Script

local RunService = game:GetService('RunService')
local Plr = game:GetService('Players').LocalPlayer
local Building = -- Path to building
local Roof = Building.Roof

RunService.RenderStepped:Connect(function()
    local isInside = false

    for _, Touching in workspace:GetPartsInPart(Building.Inside) do
        if Touching.Parent == Plr.Character then
            isInside = true
            break
        end
    end

    if isInside then
        Roof.Transparency = Roof.Transparency:Lerp(1,.2)
    else
        Roof.Transparency = Roof.Transparency:Lerp(0,.2)
    end
end)
1 Like

I will try this code, give me a couple of minutes :+1:

2 Likes

It seems to not be rendering the player being inside the building

Here is a photo of the model if you’d like it:

1 Like

Try making a part that covers the whole building or just the door, and then detect when the player touches that part. When it does, tween the roof part. It may not be the best solution, but that’s all I can think of for now.

local Info = TweenInfo.new(1)
local TweenIn = game:GetService("TweenService"):Create(script.Parent,Info,{Transparency=0})
local TweenOut = game:GetService("TweenService"):Create(script.Parent,Info,{Transparency=1})
local detection = script.Parent.Parent.Detect --part in model/building
local touching = false

detection.Touched:Connect(function()
  if touching == false then
    touching = true
    TweenOut:Play()
  else
    touching = false
    TweenIn:Play()
  end
end)

-- its just something i thought of, it might not even work lol

This was my original Idea but the problem is the player can glitch i by walking in and out real fast and then walking back in and it will appear like this:

1 Like

add a debounce to it, for the detection part

basically make it CanCollide to true and CanTouch to false, then once that debounce is over put them in their original values

1 Like

I do not have much experience with debounce. Do you mind adding that to the script for me?

1 Like

Debounce is basically like a wait, like a timer. Reading this could help you

1 Like

So how and where do I input this debounce code?

It’s because the tween takes too long and debounce won’t fix it unless you make the door collidable till tween finishes.

Think of it as a bunch of cockroaches swarming your house. You kill one, more came.

1 Like

put it in the touching line

if touching == false and debounce == false then
  debounce = true
  touching = true
  TweenOut:Play()
  wait(1)
  debounce = false
else
  debounce = true
  touching = false
  TweenIn:Play()
  wait(1)
  debounce = false
end

something like this

You need to set debounce to false at the end and to true at the start

You could make teleporters, one outside, one inside with a debounce in them. Debounce works like this:

local debounce = false
--Function
if not debounce then
debounce = true
task.wait(time_here)
debounce = false
end

that was a mistake on my end, i just realized after i posted it

Also I made a comment too if you didn’t see lol.
Also does the build mode fire once you touch the door or something?

I will try my best to be very descriptive,

This game is a zombie game, Zombies will chase you and you can loot houses to get upgrades BUT I don’t want players to be able to see whats inside the home until they enter.

Also, the doors do not close but only open so zombies can follow the player.

I dont think a telaporter would work

1 Like

A teleporter would work as long as the zombies have a humanoid, which I’m sure they do.
Just detect humanoid, if found, teleport inside.

1 Like