How do I stop players from clicking after something becomes transparent

I’m currently starting a simulator experiment, and currently I’m trying to make it so that when you click on an object it will become transparent then after some time it will not be transparent. But the thing is when it becomes transparent you are still able to click it and I don’t want players to keep clicking on it after it is transparent…?

local ClickDetector = script.Parent.ClickDetector
local Players = game:GetService("Players")

local farmChunk = script.Parent
local farmChunk2 = script.Parent.Parent.Head

ClickDetector.MouseClick:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local cropStat = leaderstats and leaderstats:FindFirstChild("Crops")
	if cropStat then
		cropStat.Value += 1
	end
	farmChunk.Transparency = 1
	farmChunk2.Transparency = 1
end)
local Players = game:GetService("Players")
local player = Players.LocalPlayer 
local mouse = player:GetMouse()
mouse.TargetFilter = workspace.Model

I set the target filter to a folder and just parent things to it

In your case
when you set it transparent you can place it into a folder for the transparent items

1 Like

Have an if statement in the Mouseclick event that stops the code from continuing if the chunks’ transparency is 1

if farmChunk.Transparency == 1 and farmChunk2.Transparency == 1 then
    return
end

And I see you’re doing a lot of posts, I would highly recommend using logic of your knowledge in lua/and also the developer wiki to figure these out as they’re simple issues

1 Like
local ClickDetector = script.Parent.ClickDetector
local Players = game:GetService("Players")

local farmChunk = script.Parent
local farmChunk2 = script.Parent.Parent.Head

ClickDetector.MouseClick:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local cropStat = leaderstats and leaderstats:FindFirstChild("Crops")
	if cropStat then
		cropStat.Value += 1
		
		farmChunk.Transparency = 1
		farmChunk2.Transparency = 1
		
		if farmChunk.Transparency == 1 and farmChunk2.Transparency == 1 then
			return
		end
		
	end
end)

Unless I’m doing it wrong is there a specific place to put it?

You put it as the first lines of code in the event, meaning before the local leaderstat line

1 Like