Returning Parameters from a function within a module script

The title is pretty much self-explanatory. How do I return a parameter value within a function inside a module script?

I really need this for my scripting creation.

Link here to my scripting Creation: https://devforum.roblox.com/t/simplezs-simple-commands-created-by-seeker4050-me-beta-reposted/906410?u=seeker4050

Here is the script. How do I do this?

Script
1. function SimpleZ.RayCast(Origin, Direction, Visualized, Radius)
2. 		
3. 		if Visualized == true then
4. 			
5. 			local ray = Ray.new(Origin, Direction)
6. 			local _, Position = workspace:FindPartOnRay(ray)
7. 			local Distance = (Origin - Position).Magnitude
8. 			
9. 			local Part = Instance.new("Part")
10. 			
11. 			Part.Name = "Visualized Ray"
12. 			Part.Anchored = true
13. 			Part.CanCollide = false
14. 			Part.Parent = game.Workspace
15. 			
16. 			Part.Material = "Neon"
17. 			Part.BrickColor = BrickColor.new("Really red")
18. 			
19. 			Part.Size = Vector3.new(Radius, Radius, Distance)
20. 			Part.CFrame = CFrame.lookAt(Position, Origin) * CFrame.new(0, 0, -Distance/2)
21. 			
22. 		else
23. 			
24. 			local ray = Ray.new(Origin, Direction)
25. 			local Hit, Position = workspace:FindPartOnRay(ray)
26. 		
27. 			return SimpleZ
28. 			
29. 		end
30. 		
31. 	end

You need to return a table of functions at the end of the script, like so:

local SimpleZ = {}

function SimpleZ.Raycast(-- params)
    -- function
    return -- values you want to return
end

return SimpleZ

You can call these functions like this:

local SimpleZ = require(-- path to ModuleScript)

SimpleZ.Raycast(-- params)

Hope this helps.

5 Likes

Thank you! I was able to call the value from another script!

Thanks!

1 Like