Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempted to call require with invalid argument(s)?

I am trying to use a variable (TimesFound2) from my script RandMove (1) in my other script Leaderboard (2)

local RandMove = {}
Increment = 1
TimesFound1 = 0
Part = game.Workspace.Brick1
TimesFound2 = 0
local debounce = false

function RandMove.RandMove(hit)
	if debounce == false then
		debounce = true
		Part.Position = Vector3.new(math.random(0, 100), 5, math.random(0, 100))
		TimesFound1 = TimesFound1 + Increment
		TimesFound2 = TimesFound1
		print(TimesFound2)
		wait(1)
		debounce = false
	end
end
 
Touched = Part.Touched:Connect(RandMove)
return RandMove

RandMove = require("RandMove")

function Score(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats
	money.Value = RandMove.TimesFound2
	
end
game.Players.PlayerAdded:Connect(Score)
Score()

It is returning the error: Attempted to call require with invalid argument(s).

4 comments

0

How can i fix this?

0

no no no the require you have to pass the module script object into the parameter

0

also do the touched event inside the local script and make sure to do randmove.randmove

0

Could you post an answer, and include the edits do i can see what you mean?

1 answer

✓ Accepted answer

require() is used to access stuff from modulescripts and nothing else. So if you wanna access a variable from the module do :

local ModuleScript = require(script.Parent.ModuleScript) -- Change it to wherever your module script is located
local variable = ModuleScript.Variable -- assuming that you named your variable Variable

To fire a function you simply need to do this :

local ModuleScript = require(script.Parent.ModuleScript) -- Change it to wherever your module script is located
ModuleScript.Function() -- Assuming that you named your function Function

This discussion is preserved as it was. New answers, comments, and votes are closed.