I need to get my script working so that when I click a ClickDetector, the UIS click does NOT activate.
As it is currently, what I have tried is changing it from CAS to UIS since I thought maybe GameProcessedEvent would be covered with the clicking a ClickDetector… But it isn’t. I have already looked for solutions and tried that one but to no avail.
If anybody knows a solution to this I’d be very grateful here is the code for it:
local uis = game:GetService("UserInputService")
local PlayerGui = player.PlayerGui
local M1 = PlayerGui:WaitForChild("ContextActionGui"):WaitForChild("ContextButtonFrame"):WaitForChild("M1")
local function M1Click()
if player.DisabledCombat.Value == false then
combatRemote:FireServer()
end
end
uis.InputBegan:Connect(function(key,x)
if key.UserInputType == Enum.UserInputType.MouseButton1 and not x then
M1Click()
end
end)
M1.MouseButton1Click:Connect(M1Click)
maybe have a bool variable and check for it when you connect the click UIS event
if they are in more than 1 script you can have that bool as an attribute or a value in a module script
ClickDetectors and UI Buttons all have RBXScriptConnections to make it easier to detect when a player has clicked the clickdetector or UI button.
Click detectors use RightMouseClick and MouseClick to detect when a player has clicked it.
Click Detector Example
Code
local CD = Instance.new('ClickDetector',workspace.SpawnLocation)
CD.MouseClick:Connect(function()
print('clicked')
end)
CD.RightMouseClick:Connect(function()
print('right clicked')
end)
Image
Meanwhile, UI buttons (TextButton, ImageButton) use Activated, MouseButton1Click, and MouseButton2Click. There are various other ways of detecting UI clicks, but these ones are much easier to use.
it’s in 2 different scripts, and this one is a localscript ofc while the clickdetector is a server script. I am not very familiar with module scripts and idk if that would be a solution, but i do not believe so because the UIS click detection would run before the ClickDetector one would?
You’re using UserInputService to detect when it clicks, that is why. UserInputService detects when input is begun and then runs the code within that connection.
ClickDetector’s only detect when the user clicks the instance itself, not across the entire universe. So you’re code runs whenever the player starts input and that input is the LMB.
I know this already, but how do I fix it-?? I have UIS doing the detection for click for my punching in combat… But I am using a ClickDetector for quest NPCs, so how do I make it so when you click the ClickDetector, it doesn’t run the UIS? (or that it doesn’t run the :FireServer() at least)
-- Only an example
local UserInputService = game:GetService("UserInputService")
local attributeLocation = workspace
local ClickDetector :ClickDetector = workspace
UserInputService.InputBegan:Connect(function()
if attributeLocation:GetAttribute("AttributeName") == true then
-- your code
end
end)
ClickDetector.MouseClick:Connect(function()
attributeLocation:SetAttribute("AttributeName", false)
end)
make the bool variable false when the click detector is clicked
i gtg rn
local ClickDetector = PATHTOCLICKDETECTOR
local PlayerGui = player.PlayerGui
local combatRemote = PATHTOREMOTE
local player = PATHTOPLAYER
local M1 = PlayerGui:WaitForChild("ContextActionGui"):WaitForChild("ContextButtonFrame"):WaitForChild("M1")
local function M1Click()
if player.DisabledCombat.Value == false then
combatRemote:FireServer()
end
end
ClickDetector.MouseClick:Connect(function()
M1Click()
end)
M1.MouseButton1Click:Connect(M1Click)
*I would also like to point out that combatRemote was never referenced in the script at all; and the player variable was never referenced as well. Without additional context of what and where the script is, I cannot provide help with “player”.
i just didn’t put those stuff in the given parts, cause they weren’t really necessary for the task at hand. Just assume it has a reference. I also think your idea of using a remote would also not work because the UIS would run before the ClickDetector could fire the remote back to the client
I HAVE FOUND A SOLUTION!! ClickDetector comes with .MouseHoverEnter and .MouseHoverLeave connections so I can use that to check when they have their mouse over the NPC and disable their combat accordingly!