Ok so I’m trying to make a tycoon on ROBLOX and I’m really struggling with the buy wall script where when you stand on the button you buy the wall, I don’t know how to make the whole model go from transparent and uncollidable to transparent and collidable, can someone please help me figure this out, i would be really grateful
Loop through the descendants of the model, check if they are a basepart, and if they are, set their cancollide to true and transparency to 0.
i dont know much about scripting, could you kinda teach me how to do that?
function modelAppear(model)
for _, v in ipairs(model:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 0
v.CanCollide = true
end
end
end
Do I have to change anything??
@Pokemoncraft5290’s example provides a function & parameter passed to require what Model
you want to exactly detect for so you’ll have to reference which model to search for using modelAppear()
, with placing the Model inside the parenthesis (Or modelAppear(ModelHere)
Another way you could do it is by just referencing the Model
as a local variable instead when you want it to make it visible when purchased
local Model = --Define your Model outside the button press event
--Do your conditional checks if the Player has enough cash/money to buy the wall
for _, Object in pairs(Model:GetDescendants()) do
if Object:IsA("BasePart") then
Object.Transparency = 0
Object.CanCollide = true
end
end
im sorry i dont want to be annoying but what do you mean by “Define your model outside the button press event” how do i do that?
Just put the model that you want to make transparent there.
The Model is what you’d want to change, so you’d change your local Model
to local Model = workspace.ModelNameHere
to properly define it
Also I heavily encourage you to learn more scripting so you can have a better understanding of how this stuff works
yeah i have been considering taking courses on it, thank you btw
i do have one more question, if i was using this script for a button would this work?
local Model = Workspace.Wall1–Define your Model outside the button press event
–Do your conditional checks if the Player has enough cash/money to buy the wall
function onTouched(hit)
if hit and hit.Parent:FindFirstChildWhichIsA(“Humanoid”) and Debounce == false then
Debounce = true
for _, Object in pairs(Model:GetDescendants()) do
if Object:IsA(“BasePart”) then
Object.Transparency = 0
Object.CanCollide = true
end
end
Yep! That’s how you order it! Although 1 thing I see is that you missed 2 ends
while ending your onTouched
function & if hit and hit.Parent
conditional checks
where would i put those ends? (sorry i know im annoying)
You could just put them at the end after you finish your loop
Something like this would do:
local Model = Workspace.Wall1 --Define your Model outside the button press event
local Debounce = false
--Do your conditional checks if the Player has enough cash/money to buy the wall
function onTouched(hit)
if hit and hit.Parent:FindFirstChildWhichIsA("Humanoid") and Debounce == false then
Debounce = true
for _, Object in pairs(Model:GetDescendants()) do
if Object:IsA("BasePart") then
Object.Transparency = 0
Object.CanCollide = true
end
end
end
end
ok so everything seems to be working but when i clicked the button the model didnt appear?
i already know that the part you wrote works cuz before when i tested it, it made it visible everytime but now that i added the whole button thing it isnt working
Wait there isn’t even anything to connect the function from lol
Try this
--Do your conditional checks if the Player has enough cash/money to buy the wall
function onTouched(hit)
if hit and hit.Parent:FindFirstChildWhichIsA("Humanoid") and Debounce == false then
Debounce = true
for _, Object in pairs(Model:GetDescendants()) do
if Object:IsA("BasePart") then
Object.Transparency = 0
Object.CanCollide = true
end
end
end
end
script.Parent.Touched:Connect(onTouched)
it still isnt working, no errors just not working
Wait, what I’m trying to make this script do is basically buy a wall like in a tycoon so I want it to go from transparent to visible and able to be touched
I’m on phone cause my PC died, but the OP is wanting to make the Wall visible upon purchasing
Gotcha. Might want to reword your title and description a bit to avoid any further confusion. First of all, are you just copy-pasting the script? You’re supposed to keep the variables from the previous script that @JackscarIitt supplied you with.
local Model = Workspace.Wall1 --Define your Model outside the button press event
local Debounce = false
--Do your conditional checks if the Player has enough cash/money to buy the wall
function onTouched(hit)
if hit and hit.Parent:FindFirstChildWhichIsA("Humanoid") and Debounce == false then
Debounce = true
for _, Object in pairs(Model:GetDescendants()) do
if Object:IsA("BasePart") then
Object.Transparency = 0
Object.CanCollide = true
end
end
end
end
script.Parent.Touched:Connect(onTouched)