Accessing script data from local script

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 TowerScript
image

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”
image

Here’s the hierarchy:
image

2 Likes

looking at you hierarchy, I’m not seeing a value for TowerScript
Are you sure it isn’t Workspace.Towers.TowerScript. then a value like a bool?

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
1 Like

I’m trying to access a function inside TowerScript, what do you mean a value for TowerScript? as in a property?

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
image

Maybe I didn’t understand what you said … you’re have problems finding BillboardGui?
is this it … local billboardGiu = script.Parent.Parent.BillboardGui

I have a problem with accessing ShowStats() function

Then you have a Model name nothing to deal with … if you go from workspace.

Sorry this is a bit cofuseing you need to show the real scripts here…
Are you missing a required call? (to the ModuleScript)

Looks like PhoenixCausesOof may be on the right track here. If this is a simple case of calling a function from the ModuleScript.

Can you clarify more please? I didn’t quite get what you mean

I think what you’re trying to do is access a function located in a normal script? You should use a modulescript for that

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

Yes, I’d do that. I don’t 100% understand the last part, perhaps you could share some of that script to help me understand


and located in StarterPlayerScripts

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()

I get an error for requesting the module script


image
image

Can you send me a pic of the module script

Sure
image

There is usually a second error above it (that is the real error message then)

1 Like

I dont think the billboardGui is in the TowerScript, I think you meant to put there

local billboardGUI = script.Parent.Parent.BillboardGui

Oh you’re right, it’s this one