What do you want to achieve? I want to create an gui where if you press an button it makes a model visible
What is the issue? I have tried searching for an answer that fits my question, to no avail
What solutions have you tried so far? I have tried several scripts, but it didn’t give me the awaited result.
I currently have a world map with borders with several time-eras, i want to make an gui where if you press one of the options, the borders become visible for yourself (client) only, and not for anyone else, the button should also be able to make the borders of said era visible aswell.
I would be glad if someone could assist me with the difficult part, once i know how to do atleast one, i can probably do the others from that point on.
Hi! So in order to do this you would just use a local script and apply the logic there. For instance, to change a part’s transparency to 0.5 you would write the following code in a local script:
local part = game.Workspace.Wall -- references the part i want to change
local button = script.Parent.Frame.Button -- references the button (the script is in the screengui)
button.MouseButton1Click:Connect(function()
part.Transparency = 0.5
end)
of course in your case, assuming that by model you mean an actual roblox model, you would simply do a for loop through the model, find the baseparts and make the change there
Like this:
button.MouseButton1Click:Connect(function(
for i, v in game.Workspace.Model:GetChildren() do
if v:IsA('BasePart') then
v.Transparency = 0.5 -- This loops through every item and checks if it's a basepart, if so then the code will carry through
end
end
end)
Therefore the end product should look something like this.
I would check if the transparency is already to set to 1 and if it is would make it 0 (visible)
and would apply the inverse if the part is not invisible, something like this
if part.Transparency == 1 then
part.Transparency = 0
else
part.Transparency = 1
end
local button, button2, button3 = script.Parent.Frame.Button, script.Parent.Frame.Button2, script.Parent.Frame.Button3
button.MouseButton1Click:Connect(function()
for i, v in game.Workspace.Folder.Wall:GetChildren() do
if v:IsA('BasePart') then
if v.Transparency == 0.5 then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
end)
button2.MouseButton1Click:Connect(function()
for i, v in game.Workspace.Folder.Wall1:GetChildren() do
if v:IsA('BasePart') then
if v.Transparency == 0.5 then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
end)
button3.MouseButton1Click:Connect(function()
for i, v in game.Workspace.Folder.Wall2:GetChildren() do
if v:IsA('BasePart') then
if v.Transparency == 0.5 then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
end)
every button has an effect on the model it’s meant to change so i would make a variable for every button and when it’s pressed I would make the changes then.
I am planning to fill this up with buttons that can enable/disable one era border at a time
I want every button to only change 1 border, every button should have a script that changes an border’s visibility
Alright. This may be inefficent but this should work
local button = script.Parent.Frame.Button -- Replace this with the button you want to check is pressed
button.MouseButton1Click:Connect(function()
for i, v in game.Workspace.Folder:GetDescendants() do
if v.Parent.Name ~= 'Wall' and v:IsA('BasePart') then -- make sure to check if it's anything other than the parent model by writing the model name rather than 'Wall'
v.Transparency = 0
else
if v:IsA('BasePart') then
if v.Transparency == 0.5 then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
end
end)