leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 31 Jul 2016 02:20 PM |
So I have this local script in StarterGui and I want to be able to pass this function to my server script so that the players mouse target can be destroyed in the server.
Here is my local script: local player = game.Players.LocalPlayer local mouse = player:GetMouse()
local MineBlock = game:GetService("ReplicatedStorage").Events:WaitForChild("MineBlock")
function Mine() local target = mouse.Target if target == nil then target = nil else target:Destroy() end end
mouse.Button1Down:connect(function() MineBlock:FireServer("Hello") end)
Here is my script in ServerScriptService:
MineBlock = game:GetService("ReplicatedStorage").Events:WaitForChild("MineBlock")
MineBlock.OnServerEvent:connect(function(plr, Test, Mine) print(plr.Name, Test) MineBlock:FireAllClients(plr,'Hello!') end) |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 02:34 PM |
You can't pass functions. You will need to find another way.
|
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 02:37 PM |
I suggest using a ModuleScript, and require the function from that ModuleScript. For example;
--Put this in the module local xmodule = {} function xmodule.fetch() print("The function in the module was fired") end return xmodule
--...And put this in the script that fires the function in the ModuleScript local ModuleScript = require(workspace:WaitForChild("ExampleModule")) ModuleScript.fetch() --Fires the function in the module
|
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 31 Jul 2016 02:40 PM |
| Wait but can I pass the mouse? |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 02:43 PM |
Nope. You can't pass the mouse. You can most likely pass the target though.
|
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 31 Jul 2016 02:45 PM |
| Alright I'll try that instead and see what I can do with it. |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 31 Jul 2016 02:52 PM |
Ok so what I'm doing seems like it could work but it isn't here is the code:
Local script:
local player = game.Players.LocalPlayer local mouse = player:GetMouse()
local MineBlock = game:GetService("ReplicatedStorage").Events:WaitForChild("MineBlock")
local target = mouse.Target
mouse.Button1Down:connect(function() MineBlock:FireServer("Hello") MineBlock:FireServer(target) end)
ServerScript:
MineBlock = game:GetService("ReplicatedStorage").Events:WaitForChild("MineBlock")
MineBlock.OnServerEvent:connect(function(plr, Test, Block) print(plr.Name, Test) local Block = Block Block:Destory() MineBlock:FireAllClients(plr,'Hello!') end) |
|
|
| Report Abuse |
|
|
Real_Edgy
|
  |
| Joined: 23 Oct 2013 |
| Total Posts: 1212 |
|
|
| 31 Jul 2016 02:54 PM |
| Your 'target' variable will hold the same thing until the script quits out. It will initialize as nil. You need to get the target _when_ you click. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 02:54 PM |
Target doesn't update when mouse.Target updates, because it essentially copies the value.
That isn't true of Instances and Tables, but of most things like strings, it only copies it.
mouse.Button1Down:connect(function() local target = mouse.Target MineBlock:FireServer("Hello") MineBlock:FireServer(target) end)
|
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 31 Jul 2016 02:58 PM |
Ah alright I understand now and now I fixed it to get target when you click but it comes out with an error in ServerScriptService:
ServerScriptService.GameEventsManager:5: attempt to index local 'Block' (a nil value) |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|