Local script not firing in workspace

I am not a good scripter but I do know enough to write “OK” scripts but today I was writing and came across an issue, I need a local script to call items in the workspace to be transparent

here is my incredibly inefficient script:

function onClicked()
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.Plant.Hedge1.Transparency = 0
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.Plant.Hedge2.Transparency = 0
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.Plant.Union.Transparency = 0
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.PlantPot.Union.Transparency = 0
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.PlantPot.Union2.Transparency = 0
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot.PlantPot.PartTransparency = 0
    script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot2.Plant.Union.Transparency = 1
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot2.PlantPot.Union.Transparency = 1
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot2.PlantPot.Union2.Transparency = 1
	script.Parent.Parent.Parent.Parent.Parent.Workspace.PlantPot2.PlantPot.Part.Transparency = 1
  end
  
  script.Parent.MouseButton1Click:connect(onClicked)

I need some help,it doesn’t work and I don’t know any other way to get it to work.

you probably don’t need a localscript… use a script instead.

You are not able to use ClickDetectors in localscripts, try running this code from a serverscript.

1 Like

but wont that make it fire for everybody else in the game?

local scripts only work in client-related objects

Im not using a click detector, im using a gui button

if you wanted to use a make the plant only visible to a certain player, move the plant to the player’s camera.

then use a normal script?

30charsbhafajkn f

using a script will fire for everyone in the game.

if you want everyone to see the plant, then use a script.

I have it where you can change the plant to another from a gui. I want it to be local so only the person clicking the change gui can see the difference

ok, then add the plant to the player’s camera to make it local to them.

I can no longer see the plant, sorry I no good at studio

Don’t think you can fire localscripts in workspace anyway.

1 Like

Try putting the script into StarterPlayerScripts, and then on the end where you connect, do this:

game.Workspace.Part.ClickDetector.MouseClick:Connect(onClicked) -- Also, use :Connect, :connect is deprecated.
       -- ^ Change this to wherever your ClickDetector is.

you know you can create variables right?

 local obj = workspace:WaitForChild("Obj")

local scripts do not run in workspace.

you can also make your code more organized by doing something like this

local objects = {

     workspace.PlantPot;
     workspace.PlantPot2;
   
 }

 for _, object in ipairs(objects) do
       for _, item in ipairs(object:GetChildren()) do -- assuming every child of PlantPot and PlantPot2 are base parts 
              item.Transparency = 1
       end
 end

you can also get workspace by using the builtin shorthand workspace so

game.Workspace = workspace

edit: @smashman65 it’s quite simple?

I just stored the objects in an array, so I can loop over them and get their children , and set their Transparency to 1

https://developer.roblox.com/en-us/api-reference/class/LocalScript
https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

oh, I forgot…

30charsnahj nkfvm,a.

im too dumb for that, im not there yet, only been learning for a few months crammed in with homework. 1 more week of school…

YOU ARE SPEAKING GIBBERISH. dumb it down plz

ooh, an array is a table

30charsdagfzgaw