I want to create a script that makes a model visible after pressing an button for an client only

  1. What do you want to achieve? I want to create an gui where if you press an button it makes a model visible

  2. What is the issue? I have tried searching for an answer that fits my question, to no avail

  3. 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.

5 Likes

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.

4 Likes

Nvm, you forgot to add an closing bracket for (function(

3 Likes

Ah yes I see the issue, my fault. To make the border invisible you have to set the transparency to 1, which will make the part invisible

4 Likes

Is it also possible to revert the transparency of said model after you’ve pressed the button?

2 Likes

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
1 Like

I am failing to combine the codes listed into 1 code and actually make it work

1 Like

Fair enough. Are you going through a model or just part(s) that are ungrouped?

1 Like

(removed image)
the situation is this as of right now

1 Like

How would you select what era you can see? Like is it 1 button that disables all or is it several buttons that disables 1?

1 Like

i would like to make every one of those a seperate button

1 Like

in the ‘modern’ folder, are there seperate buttons for country and state or is it one button affecting all?

1 Like

the Country are the country borders, the states are the subdivisions of the countries

1 Like

I would write it as this

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.

1 Like

PS. My explorer looks like this:

image

1 Like

image
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

1 Like

So every button will have it’s own script rather than one large script?

1 Like

Yep, that’s what i want, even if it’s less optimised

1 Like

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)
1 Like

I have checked, and it seems to not work

1 Like