.Activated just not firing with client-sided BillboardGui in workspace

Hello. I’ve got two buttons, one called Yes and the other No, and their .Activated events seems to not be firing.
They are .Activated == true, including their ancestors.

I really don’t see why it wouldn’t work, please help!

My code: (mind the CHECKIT comments)

-- Modules
local gameModule = require(game:GetService("ReplicatedStorage").GameModule)

-- References
local UserInputService				=	game:GetService("UserInputService")
local LocalPlayer					=	game:GetService("Players").LocalPlayer
local CurrentCamera					=	game.Workspace.CurrentCamera
local selectedBlock: ObjectValue	=	script.Parent.selectedBlock
local BuildGui						=	script.Parent.Parent
local Blocks						=	game:GetService("ReplicatedStorage").Blocks
local LocalBlocks					=	Instance.new("Folder")
local ConfirmUi						=	game:GetService("ReplicatedStorage").Gui.ConfirmUi
local BuildingZones					=	game.Workspace.Platforms.BuildingZones

LocalBlocks.Name	=	"TempLocalBlocks"
LocalBlocks.Parent	=	game.Workspace

-- Remotes & Bindables
local BuildBlockRemote	=	game:GetService("ReplicatedStorage").Remotes.Building.BuildBlock
local TimeTypeRemote	=	game.ReplicatedStorage.TimeType -- sends TimeType when match starts

-- Variables
local deleteMode = script.Parent.deleteMode

local connections = {
	onConfirmation = {},
	onClick = nil, -- declared at runtime
	onBlockSelected = nil
}

-- CONSTANTS
local LOCAL_BLOCK_TRANSPARENCY = 0.45

-- functions
local function sendBlock(Block: Instance, mousePosition)
	BuildBlockRemote:FireServer(tostring(Block), CurrentCamera.CFrame, CurrentCamera:ViewportPointToRay(mousePosition.X, mousePosition.Y))
end

local function onBlockSelect()
	if connections.onClick then
		connections.onClick:Disconnect()
	end
	local Block: Instance? = selectedBlock.Value
	connections.onClick = UserInputService.InputBegan:Connect(function(input: InputObject)

		if Block and deleteMode.Value == false and #LocalBlocks:GetChildren() == 0 then

			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				sendBlock(Block, UserInputService:GetMouseLocation())

			elseif input.UserInputType == Enum.UserInputType.Touch then
				local mousePosition = UserInputService:GetMouseLocation()
				local mouseRay = CurrentCamera:ViewportPointToRay(mousePosition.X, mousePosition.Y)

				local raycastParams = RaycastParams.new()
				raycastParams.FilterType = Enum.RaycastFilterType.Exclude
				raycastParams.FilterDescendantsInstances = {LocalPlayer.Character}
				local mouseRaycast = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * gameModule.REACH, raycastParams)

				local PlayerZone
				for count, CurrentZone in BuildingZones:GetChildren() do
					if CurrentZone:GetAttribute("userID") == LocalPlayer.UserId then
						PlayerZone = CurrentZone
					end
				end

				if mouseRaycast and gameModule.isPointInPart(
					gameModule.snapToGrid(mouseRaycast.Position, mouseRaycast.Normal),
					PlayerZone)
				then

					local NewConfirmUi = ConfirmUi:Clone()
					local LocalBlock = Block:Clone()
					LocalBlock.CanTouch = false
					LocalBlock.CanQuery = false
					LocalBlock.Position = gameModule.snapToGrid(mouseRaycast.Position, mouseRaycast.Normal)
					LocalBlock.Transparency = 1
					for _, Texture in LocalBlock:GetChildren() do -- makes all of the textures of the block transparent
						if Texture.ClassName == "Texture" then
							Texture.Transparency = LOCAL_BLOCK_TRANSPARENCY
						end
					end

					NewConfirmUi.Parent = LocalBlock
					LocalBlock.Parent = LocalBlocks

					--CHECKIT// these are the connections \\CHECKIT--
					NewConfirmUi.Frame.Yes.Activated:Once(function()
						print"hi"
						sendBlock(Block, mousePosition)
						LocalBlock:Destroy()
						print"bye"
					end)
					NewConfirmUi.Frame.No.Activated:Once(function()
						print"no hi"
						LocalBlock:Destroy()
						print"no bye"
					end)
					
					NewConfirmUi.Enabled = true
				end
			end
		end
	end)
end

-- code i think
local function activateBuilding()
	BuildGui.Enabled = true
	connections.onBlockSelected = selectedBlock:GetPropertyChangedSignal("Value"):Connect(onBlockSelect)
end

local function deactivateBuilding()
	BuildGui.Enabled = false
	if connections.onBlockSelected then
		connections.onBlockSelected:Disconnect()
	end
	if connections.onClick then
		connections.onClick:Disconnect()
	end

	for _, instance in LocalBlocks do
		instance:Destroy()
	end
end

TimeTypeRemote.OnClientEvent:Connect(function(timeType)
	if timeType[2] == 3 then
		activateBuilding()
	elseif timeType[2] == 4 then
		deactivateBuilding()
	end
end)
1 Like

What happens if you move the .Activated outside the function? I never really used events inside functions, so could this be the problem?
Otherwise, are there any errors?

1 Like

It didn’t work even before I put the connection in a function to de-nest my code. Also functions doesn’t modify events’ behavior.

1 Like

Where are you calling onBlockSelect()?

1 Like

in the activateBuilding function, line 2.
it gets called as the button appears, but it’s unclickable.

1 Like

Why are you using :Once()?

Are you disconnecting the buttons after every click?

1 Like

Walk me through the order of operations here because it’s a bit messy. I’m guessing the TimeTypeRemote remote event gets called every time you want to turn on/off the button right? Then when its activated, it waits until the selectedBlock (objectValue) has its value changed, then runs the function, which then creates another nested event onClick which only connects the .Activated connection for mobile players only if mouseRaycast and gameModule.isPointInPart are both true?

1 Like

Pretty much, except:

No, only if they are not nil.

No, only when the round period changes. (ex: building time to build checking time)

I found a solution!
Instead of parenting the BillboardGui to the client-side ghost block in workspace, I parented it to LocalPlayer.PlayerGui and set the Adornee property to the ghost block.

Also made the BillboardGui destroy separately because it isn’t a parent of LocalBlock anymore.

Maybe the Activated event for Objects in workspace relies on the server, so it doesn’t work when the Object in question is client-sided.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.