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)