Hello, I’m trying to access “ShowStats” function placed in TowerScript in the workspace from MouseHoverManager local script in the StarterPlayerScripts, however I keep getting “ShowStats is not a valid member of Script…“Workspace.Towers…TowerScript””
This is MouseHoverManager script, this snippet is from a hover function that runs everytime a raycast hits a tower and that it contains the “TowerScript”
It seems you’ve confused (normal) Scripts and ModuleScripts. ModuleScripts are the ones you should require, and Scripts are where you should require them from.
TowerScript:
local TowerModule = require(script.TowerModule)
TowerModule.ShowStats()
...
TowerModule:
local BillboardGui = script.Parent.Parent.BillboardGui
local module = {}
function module.ShowStats()
BillboardGui.Enabled = true
end
return module
Oh I’m sorry the snippet seemed to be misleading, ignore the module script that’s a child of TowerScript I’m not using this one, in fact I’m using a local script in StarterPlayerScript
Maybe I didn’t understand what you said … you’re have problems finding BillboardGui?
is this it … local billboardGiu = script.Parent.Parent.BillboardGui
So should I have the function in the module script and require it in the normal script? but I have some functionality that needs to be fired in a local script so that it’s only visible for the local client, and the ShowStats function is included
Move the ShowStats function into a module inside Towerscript
then replace line 22-24 with this
local towerScript = result.Parent:WaitForChild("TowerScript")
local towerModule = require(towerScript.TowerModule) --Module name
towerModule.ShowStats()