generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

ClickDetecter annoyance

Previous Thread :: Next Thread 
BlockDeleted is not online. BlockDeleted
Joined: 31 May 2014
Total Posts: 291
15 Jan 2017 12:13 AM
So it annoys me how even if you right click a click detector it activates the script...

Does anyone know a way for the script to only activate when you left click? Thx in advance.
Report Abuse
iJacobness is not online. iJacobness
Joined: 20 Jan 2014
Total Posts: 4944
15 Jan 2017 12:14 AM
mouse hover and using player:getmouse() or uis


Report Abuse
BlockDeleted is not online. BlockDeleted
Joined: 31 May 2014
Total Posts: 291
15 Jan 2017 12:19 AM
A little more explaining would be nice.. im kind of new to scripting.
Report Abuse
BlockDeleted is not online. BlockDeleted
Joined: 31 May 2014
Total Posts: 291
15 Jan 2017 12:30 AM
bump
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
15 Jan 2017 12:54 AM
player mouse
mouse.Target
mouse.Button1Down

search it up in the wiki.


#code self = nil
Report Abuse
Swordlust is not online. Swordlust
Joined: 05 Dec 2016
Total Posts: 476
15 Jan 2017 01:04 AM
Mhm keep in mind you can still add a clickdetector in the part without adding the function, and you can use a mouse.Button1Down function to trigger what happens as well.


Tips are always good | https://www.roblox.com/catalog/588125527/Tip
Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
15 Jan 2017 01:53 AM
local mouse = game.Players.LocalPlayer:GetMouse()
local buttonClickedEvent = game.ReplicatedStorage:WaitForChild("ButtonClickedEvent")

mouse.Button1Down:connect(function()
if game.Players.LocalPlayer.Character and mouse.Target then
local clickDetector = mouse.Target:FindFirstChildOfClass("ClickDetector")
if clickDetector and game.Players.LocalPlayer:DistanceFromCharacter(mouse.Target) == clickDetector.MaxActivationDistance then
buttonClickedEvent:FireServer(mouse.Target)
end
end
end)



--Server code inside the button:

function onClicked(player)
--Your code here
end

game.ReplicatedStorage.ButtonClickedEvent.OnServerEvent:connect(function(player, button)
if script.Parent == button then
onClicked(player, button)
end
end)


Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
15 Jan 2017 01:55 AM
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local buttonClickedEvent = game.ReplicatedStorage:WaitForChild("ButtonClickedEvent")

mouse.Button1Down:connect(function()
if player.Character and player.Character.Parent == workspace and mouse.Target then
local clickDetector = mouse.Target:FindFirstChildOfClass("ClickDetector")
if clickDetector and player:DistanceFromCharacter(mouse.Target.Position) <= clickDetector.MaxActivationDistance then
buttonClickedEvent:FireServer(mouse.Target)
end
end
end)



--Server code inside the button:

function onClicked(player)
--Your code here
end

game.ReplicatedStorage.ButtonClickedEvent.OnServerEvent:connect(function(player, button)
if script.Parent == button then
onClicked(player, button)
end
end)


Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
15 Jan 2017 01:57 AM
Put the code at the top in a localscript inside of the StarterPlayerScripts. Put the bottom code inside a regular script inside of the button/object that is being clicked on and put the code from your old script where it says "Your code here". Also make sure to put a ClickDetector object inside of the button/object.


Report Abuse
BlockDeleted is not online. BlockDeleted
Joined: 31 May 2014
Total Posts: 291
19 Jan 2017 10:52 PM
thx guys
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image