Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Local Script to Module Script

Asked by 10 years ago

So in my game i'm trying to use a Local Script in a tool to access a function in a Module script. However, no matter what I try, the Local Script just wont work.

More Explanation.

The below local script is found in a tool. Without the Module requirement, the script will run just fine, except that it will not execute the command PlayerModule.EditVoxel("Remove",targ). I know that the syntax is not the problem, because a script in workspace also accesses the Game.ServerScriptService.TerrainFunctions.EditVoxel("Remove",targ) and works just fine.

So my major theories are these, and I would be grateful if someone gave me some advice. Thanks! 1) A Module script cannot have the require command given to it more than once. 2) A local script in a player's backpack can't communicate with a Module Script. 3) A local script cannot find the script in ServerScriptService, which is unlikely because the script will not work even if I put it somewhere else.

So I moved the Module Script into ReplicatedStorage instead of ServerScriptService, and updated the Local Script as such. However, the script will still not function correctly. The Local Script is within the backpack. So is the anything about Module Scripts that stop a tool from accessing a function?

------------------The entire script will not make it past this point
local PlayerModule=require(Game.ServerScriptService.TerrainFunctions)
------------------
local debounce=true
local on=script.Parent.Name
local reload=1

function msg(Waitt,msg)
local Mg=Instance.new("Message")
Mg.Text=msg
Mg.Parent=game.Workspace
wait(Waitt)
Mg:remove()
end

function onActivated(mouse)
if debounce==false then return end
local targ=mouse.Target
slash()
if targ~=nil then
if targ.Parent~=nil then
msg(1,"Run1")
PlayerModule.EditVoxel("Remove",targ)
msg(1,"Run2")
end
end
debounce=false
script.Parent.Name="Resting"
wait(reload)
debounce=true
script.Parent.Name=on
end

function slash()
local anim=Instance.new("StringValue")
anim.Name="toolanim"
anim.Value="Slash"
anim.Parent=script.Parent
end

function onEquipped(mouse)
script.Parent.Activated:connect(function() onActivated(mouse) end)
end

script.Parent.Equipped:connect(onEquipped)

Answer this question