I made a part that when clicked has a decal spawn on it.
But i want the decal to become transparent after i click the part again.
I couldn’t make it happen though i’ve tried adding another function that makes the decal transparent but that doesn’t work. I also tried to bind the action to another function using the rightclick event but that also didn’t seem to work. So i’ve settled for this script
It works fine but not how i intended it to be.
Providing your code in a code block
is actually way better than sending it as plain text or in a screenshot.
local mebet = game.Workspace.mebet
local detector = mebet.ClickDetector
local b = Instance.new(“Decal”)
b.Texture = “rbxassetid://12301649832”
b.Parent = mebet
b.Face = Enum.NormalId.Top
function clicked()
if b.Transparency == 0 then
b.Transparency = 1
else
b.Transparency = 0
end
end
detector.MouseClick:Connect(clicked)
I don’t get how to use codeblocks on this site
Use the “`” character thrice. Or once between a sentence.
These aren’t valid quotation mark characters. If you paste this code into ROBLOX Studio, its script editor won’t recognize them. Where did those specific quote characters even come from? Are you using some type of obscure keyboard?
I just copy-and-pasted the first version of the OP’s post. It was the plain code. I am on mobile.
You can change the transparency to fix your code.
Fixed code:
--//Variables
local mebet = workspace.mebet
local ClickDetector = mebet.ClickDetector
local Decal = Instance.new("Decal")
Decal.Texture = "rbxassetid://12301649832"
Decal.Face = Enum.NormalId.Top
Decal.Parent = mebet
--//Functions
ClickDetector.MouseClick:Connect(function()
Decal.Transparency = Decal.Transparency == 1 and 0 or 1
end)
Alright… here is what is wrong with your code, dude.
- Quotation marks are fine, in the screenshot at least.
- You are creating a new instance of a decal each time you click it
- There’s an unnecessary wait statement in there-
@Katrist beat it to me, they fixed the code for you!
wouldn’t the decal need to spawn with transparency 0 so that it would look like you are spawning the decal when first clicking?
My function already adjusts for the transparency so it wouldn’t matter.
I thought so. The quotation marks on mobile tend to be entirely different characters.
Try this:
function clicked()
local decal = mebet:FindFirstChildWhichIsA("Decal") or Instance.new("Decal", mebet)
decal.Texture = "rbxassetid://12301649832"
decal.Face = Enum.NormalId.Top
task.wait(1)
if decal.Transparency == 0 then
decal.Transparency = 1
else
decal.Transparency = 0
end
end