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

7 comments
now i get this error: Infinite yield possible on 'ServerScriptService:WaitForChild("CollectableManager")'
Updated my answer, sorry about that.
I did the changes you asked but still getting same error :( Infinite yield possible on 'ReplicatedStorage:WaitForChild("CollectableManager")'
Are you sure your module is called CollectableManager?
That's the only problem I can think of.
Yeah i added my explorer photo to my post too
What's your new module variable?