|
| 02 Sep 2015 02:30 PM |
It says it will not be replicated when I click a part with one in. A server script uses it, though.
How do I get past this? |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2015 02:33 PM |
| Detect the event on the client instead, and use RemoteEvents. |
|
|
| Report Abuse |
|
|
| |
|
ausmel105
|
  |
| Joined: 05 Oct 2010 |
| Total Posts: 251 |
|
|
| 02 Sep 2015 02:44 PM |
This uses the local players mouse to detect the click, it's the most efficient way in my opinion.
In the following example I have a remote event in my Workspace named "clickdetector".
So you would put the following code into a local script, in a location which will be transferred to the player. StarterPlayerScripts is probably your best option.
local player = game.Players.LocalPlayer local mouse = player:GetMouse()
mouse.Button1Down:connect(function() if mouse.Target then if mouse.Target.Parent then if mouse.Target:findFirstChild("ClickDetector") ~= nil then workspace.clickdetector:FireServer(mouse.Target:findFirstChild("ClickDetector")) end end end end)
And a script as a child of the clickdetector:
local sp = script.Parent
workspace.clickdetector.OnServerEvent:connect(function(player, object) if object == sp then -- STANDARD CODE HERE, WITH THE PLAYER WHO CLICKED BEING "PLAYER" end end)
Any questions just ask :) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2015 03:13 PM |
@aus
that would not work and is completely broken |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2015 03:53 PM |
| anyone else? i mean these are good suggestions but i need to see it done. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 02 Sep 2015 03:55 PM |
| Connect on the client, fire to the Server. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2015 03:56 PM |
| okay eLunate, but how would i detect ANY clickdetector? what kind of setup would I need, or would it be somewhat similar to what that guy said above? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 02 Sep 2015 04:01 PM |
| LocalScript -> Player -> ClickDetector.Clicky >> FireServer -> OnServerEvent >> Context Code |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2015 04:01 PM |
| Create a remote event and when you click the click detector fire the remote event |
|
|
| Report Abuse |
|
|
ausmel105
|
  |
| Joined: 05 Oct 2010 |
| Total Posts: 251 |
|
|
| 02 Sep 2015 05:15 PM |
@Deaf
I think you'll find that it does in fact work you should try it before commenting on something without any experience. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 12:46 AM |
| aus, it wouldn't work because ClickDetectors don't have OnServerEvent or FireServer. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 12:49 AM |
| Why use ClickDetectors anyway? They're silly if you ask me, I just prefer doing all that work from mouse.Target |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 12:54 AM |
| That's a good point, actually. I think I'll make my own kind of clickdetector. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 12:55 AM |
Yeah, they're for early in your development life
So much more flexibility with "custom" ones aka mouse.Target |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:00 AM |
| so would I do a mouse.Button1Down event and check if there's a certain target/object, or use a loop? i'd like to know how to change the mouse cursor too. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:02 AM |
mouse.Button1Down:connect(function() local targ = mouse.Target if targ and targ.Parent and targ.ClassName=="Part" then -- ogm u click part good job end end)
You can also do nifty stuff with this with TargetSurface and UnitRay |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:07 AM |
| Ooh, that could be helpful. Thanks! |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:09 AM |
| But, say I wanted it to change my mouse cursor when I hover over it, would I use a loop or is there an event? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:11 AM |
Set up something like this on RenderStepped is what I'd do:
RunService.RenderStepped:connect(function() local targ = mouse.Target if targ and targ.Parent and targ.ClassName == "Part" then -- icon end end) |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:17 AM |
| Would it not lag? I don't use those loops often, but I mean it shouldn't as long as I've done it efficiently, right? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 01:17 AM |
| For just changing an icon if you're hovering over a part? No reason for it to lag |
|
|
| Report Abuse |
|
|
| |
|