I need help with a clickdetector

I’m trying to make it so when I click a button, a part changes its transparency to 0, and when I click it again, it goes back to 1.
I’ve only managed to make it go to 0 but I can’t find a way to make it go back up to 1 once I press it again.
I have Filtering Enabled so I made a Remote Event script and one in StarterGui

  1. LocalScript in StarterGui:

local clickdetector = game.Workspace.Part.ClickDetector

  1. Script in the RemoteEvent

game.Workspace.Part2.Transparency = 1

Can someone tell me how to do it?

1 Like

There’s really no need to parent the LocalScript to starter GUI. I think it’d be an easier option to just parent it to the brick itself.

-- client
local transparencyChangeEvent = game:GetService("ReplicatedStorage"):WaitForChild("ChangeBrickTransprency")

local brick = scirpt.Parent
local clickDetector = brick:WaitForChild("ClickDetector")

-- server
local transparencyChangeEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
transparencyChangeEvent.Name = "ChangeBrickTransparency"

transparencyChangeEvent.OnServerEvent:Connect(function(player, brick)
    if brick.Transparency == 0 then
        brick.Transparency = 1
        brick.Transparency = 0

Why would you advise against MouseClick? As long as it’s detected by the client, and fired to the server, there’s no performance issues.

1 Like

thing is, im trying to make it so when I click a button, the transparency of another brick changes. so this script doesnt work

I was under the impression that ClickDetectors aren’t subject to FilteringEnabled - at least if a client activates a click detector, it will fire MouseClick on the server.

This means that you would not need a localscript.

1 Like

Parent an LocalScript to an part? Wait a sec, let me see something… Oh yeah, here you go:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack, such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts.
  • The ReplicatedFirst service

I’am going to get in the roblox studio, to find a solution for this.


Why use local script? I think this is just making it a problem. Just put a normal script and the ClickDetector inside that part, you’ll need no Remote Events.

You have to define the variable brick. Something similar to this statement:

local brick = game.Workspace:WaitForChild("Brick")
1 Like

Aight, i done something, i used FireAllClients(), is that ok? But it seems to have worked:

--Put the event "ChangeBrickTransparency" in Replicated Storage.
--Name the event "ChangeBrickTransparency", "CBT"
--ServerScript in ServerScriptService.
--LocalScript, in StarterPlayerScripts.

local Part = game.Workspace.Part

local CBT = game.ReplicatedStorage:WaitForChild("CBT")

	if Part.Transparency == 1 then
		Part.Transparency = 0
	elseif Part.Transparency == 0 then
		Part.Transparency = 1

Tell me if it works, at least for me it works fine.

where do I find the ChangeBrickTransparency event?

What you mean with “find”? Just put it in Replicated Storage and name it what i told you, then it may work just fine.

well, problem is, i dont know how

You don’t know how to drag or name an object/instance?

i know, i just dont know what you mean by “ChangeBrickTransparency event”

Wasn’t that what the event is called? Nevermind, i guess the “ChangeBrickTransparency” doesn’t exist, instead of that, just name the Remote Event you used earlier, then do what i told you.

Hello? Newer Roblox games now are FilteringEnabled, and I’m pretty sure the one I made few days ago are FilteringEnabled and using ClickDetector without local script is fine.