Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change the properties multiple parts in workspace?

How do you change the properties multiple parts in a workspace? I'm making a gui where you press a button and it turns all the parts in workspace to transparency 0.5 I tried this

function click()
for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") then
v.CanCollide = false
end
end
end

but it doesn't work. Any help?

3 answers

✓ Accepted answer

Create a RemoteEvent in Replicated Storage

Next make a script in ServerScriptService

In that script goes(this shouldnt be a local script)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function()
	for i,v in pairs (game.Workspace:GetChildren()) do
		if v:IsA"Part" then
			v.CanCollide = false
		end
	end
end)

Next the script inside the button (should be a localscript)

Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.MouseButton1Down:connect(function()
	Event:FireServer()
end)

10 comments

0

he fires that when the player clicks a button i think

0

oof fair point

0

It activates before the button is clicked

0

oh

0

where is the script located

0

in a gui

0

in a button?

0

yeah

0

Fixed

0

dont forget the baseplate is a part

if your game is filtering enabled then make a remote function in replicated storage name it transparent this script is for the local script in the gui

button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.transparent:FireServer()
end)

put another script in server script service then add this

game.ReplicatedStorage.transparent.OnServerEvent:Connect(function(plr) 
for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") then
spawn(function() --makes it so they all change at the same time 
for i = 1, 0.4, -0.1 do
v.Transparency = v.Transparency + 0.1
wait()
end
end)
		end
	end
end)

if you dont have filtering enabled just do this

button.MouseButton1Click:Connect(function()
for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") then
spawn(function() --makes it so they all change at the same time 
for i = 1, 0.4, -0.1 do
v.Transparency = v.Transparency + 0.1
wait()
end
end)

I would use GetDecendants() instead of GetChildren() since GetChildren() only gets the top layer. Also use workspace instead of game.Workspace incase workspace is renamed.

Server script:

function click()
	for i,v in pairs (workspace:GetDescendants()) do
		if v:IsA("Part") then
			v.Transparency = 0.5
		end
	end
end
workspace.click.OnServerEvent:Connect(click)

Local script:

script.Parent.MouseButton1Click:connect(function()
workspace.click:FireServer()
end)

setup

Hope this helped! -ThisIsAnAccount255

This discussion is preserved as it was. New answers, comments, and votes are closed.