#Transparency

1 messages · Page 1 of 1 (latest)

inland pivot
#

Trying to make a script which makes my models invisible but they keep appearing - lights GUI and all.
How do I make the parts invisible until an upgrade in an upgrade tree is bought and unlocks the new upgrade, thus making it visible and clickable?

jagged vigilBOT
#

studio** You are now Level 1! **studio

storm tundra
#
-- not functional code! just pointers/examples
-------------------------------------------
-- setting a model's transparency example

local function modelTransp(model, transp)  -- get descendants of model
    
    for _, descendant in pairs(model:GetDescendants()) do -- descendants is everything under the model object, while children are... children
        if descendant:IsA("BasePart") or descendant:IsA("MeshPart") then  -- not sure what parts your model has.. but you can add stuff like decal, surface gui, etc
            descendant.Transparency = transp  -- set transparency, keep in mind transp' properties for different parts may be different, like ImageTransparency, etc.
        end
    end
    
end

-------------------------------------------
-- modelTtansp examples:
-- example 2:
local myModel = game.Workspace["Bob the Npc"] -- define your model somewhere/somehow

modelTransp(myModel, 1) -- first input is the model, second is the transp' value, 1 being invisible
#
-------------------------------------------
-- making a click det clickable, or a proximity prompt enabled

-- !!! note that you wont have to define your model over and over if its a global variable, which it should be lol

-- for making something clickable, you can use a click detector object inside the model, or better yet a 'hit/click box' that surrounds the model
-- you can use a cd/db (cooldown/debounce)-like system to 'enable' clicking, though if you use a proximity prompt you can disable/enable it with .Enabled = true/false
-- i call it "cd/db-like system" but I hear it be called a "bool variable", or a "switch variable", but i'm not sure :D

-------------------------------------------
--  click detector example (given this is likly inside some sort of funciton)

local myModel = game.Workspace["Bob the Npc"] -- define your model somewhere/somehow
local myClickDet = myModel.ClickHitBox.ClickDetector -- get your click det, mine is inside a click/hit box that surrounds the character/model
local canClick = false -- set a false variable

-- lets say we ran the code to make the model visible using the 'transp' function at the top
modelTransp(myModel, 0) -- 0 being visible

-- if we want the player to be able to click now that the model is visible, lets set canClick to true
canClick = true

myClickDet.MouseClick:Connect(function()
    if canClick then
        -- code to run when clicked successfully :D
    else
        -- this can be for debugging
        warn("Click value is", canClick) -- should ideally print "Click value us false!" if canClick is not set to true & the player tries to click
    end
end)