How to make UI appear after a color has a certain transparency

I’m trying to make it so when a part has a transparency of 0.1, a UI frame will pop up. I’m not sure why my code isn’t working.

local orb = game.Workspace:FindFirstChild("Orbz")
local frame = game.StarterGui.ScreenGui.Frame

if orb and orb:IsA("Part") then
	if orb.Transparency == 0.1 then
		frame.Visible = true
	else
		frame.Visible = false
	end
else

	frame.Visible = false
end
3 Likes

This currently only checks when the player loads in, so if the part’s transparency isn’t 0.1 upon loading in, it won’t show.
You can use :GetPropertyChangedSignal() with “Transparency” as the property and have it check with your current if statement.

1 Like

What @Tylerisawsome113 said. To fix it, just do this, with GetPropertyChangedSignal:

local orb = game.Workspace:FindFirstChild("Orbz")
local frame = game.StarterGui.ScreenGui.Frame
orb:GetPropertyChangedSignal("Transparency"):Connect(function()
if orb and orb:IsA("Part") then
	if orb.Transparency == 0.1 then
		frame.Visible = true
	else
		frame.Visible = false
	end
else

	frame.Visible = false
end
end)
1 Like

I tried updating my code to use GetPropertyChangedSignal and also tried your code, but doesn’t seem to be working. Maybe these screenshots can help?

image
image

1 Like

Oh! Thats because your using StarterGui. Is there a reason why you are using a serverscript?

You need to use RemoteEvents for this.

1 Like

What I want is when a player clicks a part, the the transparency turns to 0.1 (already have the code for it) and then when transparency turns 0.1, a ui pops up. Where do I put the screengui besides StarterGui?

You don’t. StarterGui is cloned when a players Joins into PlayerGui. So We need to get that Players PlayerGUI which will use remote events

I’m not too familiar with remove events. Can you please guide me with that?

Sure. First can you slide me that click detector script. We need to get the player thats clicks it before anything, as when using remote events, we need to mention a client

local Orbz = game:GetService("Workspace"):WaitForChild("Orbz")

local object = script.Parent
local clickdetector = script.Parent.ClickDetector

clickdetector.MouseClick:Connect(function(player)
	if player then
		local char = player.Character or player.CharacterAdded:Wait()
		local tool = player.Backpack:FindFirstChildWhichIsA("Tool")
		local at = game:GetService("Workspace"):WaitForChild("ar")
		print(tool.Name)
		if tool and tool.Name == "ToolA" then
			script.Parent.Transparency = 0.1
			at.BrickColor = BrickColor.new("Hot pink")
			tool:Destroy()
		end
	end
end)

Server Script:

local Orbz = game:GetService("Workspace"):WaitForChild("Orbz")

local object = script.Parent
local clickdetector = script.Parent.ClickDetector
local RemoteEvent = nil --replace with remote event pathway
clickdetector.MouseClick:Connect(function(player)
	if player then
		local char = player.Character or player.CharacterAdded:Wait()
		local tool = player.Backpack:FindFirstChildWhichIsA("Tool")
		local at = game:GetService("Workspace"):WaitForChild("ar")
		print(tool.Name)
		if tool and tool.Name == "ToolA" then
			script.Parent.Transparency = 0.1
          RemoteEvent:FireClient(player)
			at.BrickColor = BrickColor.new("Hot pink")
			tool:Destroy()
		end
	end
end)

Local script inside the GUI:

local RemoteEvent = nil -- replace with pathway to remote!
local orb = game.Workspace:FindFirstChild("Orbz")
local frame = --"game.StarterGui.ScreenGui.Frame" Change it to the pathway of the frame with script.Parent(s)
RemoteEvent.OnClientEvent:Connect(function())
if orb and orb:IsA("Part") then
	if orb.Transparency == 0.1 then
		frame.Visible = true
	else
		frame.Visible = false
	end
else

	frame.Visible = false
end
end)

All you need to do is make a Remote event, give it a name, and change it (and anything else) in both of these scripts. Remote Events works by Sending a signal to the client, and allowing the client to run code. Server is like a master client that effects everyone, and the client is what you see. So as a safety issue, roblox seperates the server from the clients. So that leaves remote events being important, as that can work through the filter! So we just listen for that to happen. You can learn more here on remote events!

1 Like

Do I put the first code you provided in ServerScriptService?

First code is just your click detector code. idk where you put that to make it work, but shouldn’t matter as long as its a server script, and inside a container that runs server scripts

I have the click detector code inside the “Orbz” part and the local script under ScreenGui

1 Like

The click script for the Part:

--Parented inside the Part
script.Parent.ClickDetector.MouseButton1Click:Connect(function()
    script.Parent.Transparency = 0.1
end)

The UI script:

--Parented inside the ScreenGui
workspace.Part:GetPropertyChangedSignal("Transparency"):Connect(function()
    if workspace.Part.Transparency == 0.1 then
        script.Parent.Frame.Visible = true
    end
end)

I have had past issues with the :GetPropertyChangedSignal() function, so this might not work.

I got this error for the click detector code

You don’t really need RemoteEvents for this.

You need to make a remote event. Like the instance. A common place in rep. stroage.

You don’t.

The Part’s transparency gets changed, let the local script detect that change, there doesn’t have to be communication between those scripts.