So before you think I am dumb, I am talking about variables you add for example:
tool.Activated:Connect(function( this part is what im talking about )
I don’t know how to do it when using ModuleScripts, I am using a module script and I want to get the mouse position. But I don’t know how to add variables to module scripts.
I’ve tried to add variables in the module script because I thought since they are already connected, it might as well. But it didn’t work. I don’t think you would need the script for this, I just want to know how to add those variables.
I hope its not gibberish. Anything is appreciated.
Well, first of all i think you’re talking about arguments, this is returned by the executed function.
These are passed when you first execute a function, for instance.
function abc.DoSomething(what) <-- argument received
print(what)
end
abc.DoSomething("Print_Eat") <-- this right here is the argument passed
So you know when you do a function like, here is an example
tool.activated:Connect(function( This is the variable part im talking about )
I want to add that but for a module script, because I want to print a mouse position from a module script. I am adding explosions and I thought that Modulescripts would be cleaner to use. And less resourceful.
MousePos still prints nil when I use that, here lemme send my scripts.:
Script I am calling it from:
local tool = script.Parent
local OnActivated = tool:WaitForChild("OnActivated")
local FireModule = tool:WaitForChild("FireModule")
OnActivated.OnServerEvent:Connect(function(plr, gunPos, mosPos)
local myModule = require(FireModule)
myModule.myFunc()
end)
Module Script (when I used your example):
local module = {}
local tool = script.Parent
module.myFunc = function(plr, gunPos, mosPos) -- where i thought you were talking about
print("get nerdbodded idiot")
tool:WaitForChild("Handle").Fire:Play()
tool:WaitForChild("OnActivated").OnServerEvent:Connect(function(plr, gunPos, mosPos)
print(gunPos)
print(mosPos)
end)
end
return module
Are you saying that myModule.myFunc(plr, gunPos, mosPos) still prints out nil? If so, that means the data you’re getting from the clientscript firing the event is also nil or empty.
Yea basically. Sorry my explanations arent the best… I will send the local script.
local tool = script.Parent
local Module = tool:WaitForChild("FireModule")
local OnActivated = tool:WaitForChild("OnActivated")
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function(mouse)
OnActivated:FireServer()
end)
Well that’s because gunPos and mosPos isn’t a variable…
Please learn more about luau or Roblox coding in general, if you knew at least basic coding, you would know that gunPos and mosPos has to be initiated or assigned to at least something. In this case, you’re assigning the parameter with “gunPos” and “mosPos” which doesn’t exist at all.
If you’re new to scripting, start small. What you’re dealing with right now is pretty complex. Practice with small stuff, then gradually work on bigger and bigger projects.
A little harsh, sorry I get a little sensitive. Sorry for the off topic. But anyway I think I fixed it? I added a variable getting the mouse’s position. So the comment did help, I realized I needed to make a variable for it.
I’d say I am getting into pretty advanced stuff, I am learning the basics. I was just tired so I think that’s the reason why I didn’t realize it. I know most of the basics and I think I’ve mastered it.
The “.Button1Down” event of the mouse object doesn’t have any parameters. If I understood correctly I believe you were just trying to send the tool’s handle’s position and the mouse’s position to the server (when a mouse click occurred).