How do you make local bricks that get more transparent as you get closer?

Hello I want to make a brick only one player can see it and also I want to make a brick that I you get closer, it gets more transparent. Any way to make this work?

Thanks

Kristian993876674778

1 Like

Take note that scripting support is not the place to ask for code nor expect it to come for free. You must attempt it yourself and come back when you run into issues.

To give you a place to start looking, check out these developer hub pages:

Local Script

Player

Edit:
Since this is relatively simple, I guess I could show you how to accomplish it

|Local Script|
local Players = game:GetService("Players") --this is different from "Player" which I linked
local Player = Players.LocalPlayer --this is the player that I linked

local Part = workspace.Part --or create it locally
local Offset = 10 --so the player doesn't have to be so close to the part just to make it transparent

while true do
    local Distance = Player:DistanceFromCharacter(Part.Position) --we get the distance of the player's character from the part
    if Distance then --we check if distance can be obtained because this can cause errors sometimes (mentioned in the developer hub page)
        Part.Transparency = (-1 + (Distance - Offset) / 10)*-1 --set the transparency of the part relative to the character's distance
        -- i can't really explain the math, but it works :P
    end
    wait()
end
4 Likes

Oh ok I’m new in this forum sorry

1 Like

I updated my reply because I realized the code did the complete opposite.

1 Like

thanks i’m gonna try it out. Can’t wait

1 Like

So where to put the script in because i put it in a part

This only works in a local script. Local scripts only run when they are placed in:

  • Backpack
  • PlayerGui
  • StarterPlayerScripts → PlayerScripts
  • StarterCharacterScripts → Player’s Character

I don’t remember the rest, but this is pretty much most if not all of it.

Ideally, you would place this script in StarterPlayerScripts

1 Like

thanks now it works. its amazing