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

Why i get ModuleScript, is not a valid member of ServerScriptService error?

I was trying to call my Modulescript from my other script but im getting this error:

22:46:49.361 - CollectableManager is not a valid member of ServerScriptService

22:46:49.362 - Stack Begin 22:46:49.362 - Script 'Players.emay0660.PlayerGui.ToolScript', Line 4

22:46:49.362 - Stack End

My explorer: https://imgur.com/xyyDVmi

I'm trying to call the CollectableManager from ToolScript.

ToolScript:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local toolEvent = ReplicatedStorage:WaitForChild("ToolEvent")
local module = require(game.ServerScriptService["CollectableManager"])


-- local Variables
local player = game.Players.LocalPlayer
local keyGui = player.PlayerGui:WaitForChild("keyGui")
local char = player.Character
local refreshTimer = 1 

UserInputService.InputBegan:Connect(function(input, gameProcessed)
      if input.UserInputType.Name == "Keyboard" and gameProcessed == false then
        if input.KeyCode.Name == "E" then
            local tool = module.Search()
            if tool then
                toolEvent:FireServer(tool)
                keyGui.E.Visible = false
            end
        end
    end
end)
while wait(refreshTimer) do
    local tool = module.Search()
    if tool then
        keyGui.E.Visible = true
    else
        keyGui.E.Visible = false
    end
end

CollectableManager(ModuleScript):

local module = {}

	function module.Search()
	local player = game.Players.LocalPlayer
	local char = player.Character
	
	local tools = workspace:WaitForChild("Collectables"):GetChildren()
	local min = nil
	local tool = nil
	
	for i = 1, #tools do
		local handle = tools[i]:FindFirstChild("Handle")
		if handle then
			local mag = (char.HumanoidRootPart.Position - handle.Position).magnitude
			if min == nil or mag < min then
                min = mag
                tool = tools[i]
            end
		end
	end
	if min then
		if min < 5 then
			return tool
		end
	end
end
return module

1 answer

EDIT:

After reading your script more carefully I see that you're trying to require a module which is in ServerScriptService from a LocalScript. LocalScripts do not have access to ServerScriptService. Move the module to ReplicatedStorage (Where LocalScripts have access to) and try requiring it again.

7 comments

0

now i get this error: Infinite yield possible on 'ServerScriptService:WaitForChild("CollectableManager")'

0

Updated my answer, sorry about that.

0

I did the changes you asked but still getting same error :( Infinite yield possible on 'ReplicatedStorage:WaitForChild("CollectableManager")'

0

Are you sure your module is called CollectableManager?

0

That's the only problem I can think of.

0

Yeah i added my explorer photo to my post too

0

What's your new module variable?

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