Why isn't it a "valid member"?

Hi! I’m the build guy, and I’m confused why it’s not thinking GiveStand is part of it. This is the code.

Activate - Script - Tool
script.Parent.Activated:Connect(function()
	local Character = script.Parent.Parent
	local Soul = game.ServerStorage.AdminSoul:Clone()
	local Motor = Instance.new("Motor6D")
	local Torso = Character:WaitForChild("Torso")
	Soul.Parent = Character
	Motor.Parent = Torso
	Motor.Part0 = Torso
	Motor.Part1 = Soul.ToolHitbox
	Motor.Name = "SoulTool"
	for i,Part in pairs(Soul:GetChildren()) do
		Part.Parent = Character
	end
	Soul:Destroy()
	for i,Part in pairs(script.Parent.Handle:GetChildren()) do
		if Part:IsA("BasePart") then
			Part.Transparency = 1
		end
	end
	Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(script.Parent.Use):Play()
	wait(4)
	game.ServerStorage.StandModule:GiveStand(game.Players:GetPlayerFromCharacter(Character),script.Parent:GetAttribute("Stand"))
	script.Parent:Destroy()
end)
StandModule - ModuleScript - ServerStorage
local module = {}

function module:GiveStand(Player,Stand)
	local StandData = game:GetService("DataStoreService"):GetDataStore("Stand")
	local StandFolder = Instance.new("Folder")
	local Stand = game.ServerStorage.Stands:FindFirstChild(Stand)
	Stand.Parent = StandFolder
	StandFolder.Parent = workspace
	StandFolder.Name = Player.Name
	local success, err = pcall(function()
		StandData:SetAsync(Player.UserId,Stand.Name)
	end)
	if success then
		print("Saved " .. Player.Name .. "'s stand as " .. Stand.Name .. ".")
	end
	if err then
		warn("Failed to save " .. Player.Name .. "'s stand as " .. Stand.Name .. " :(")
	end
end

return module

Error: “22:43:47.134 GiveStand is not a valid member of ModuleScript “ServerStorage.StandModule” - Server - Activate:22”

1 Like

The error is indicating that the script is trying to index “GiveStand” inside of the ModuleScript – this is occurring because the code you provided is referencing the location of the ModuleScript instead of accessing the table that it returns.

In order to access the function from the ModuleScript, you need to require it, instead. This means that the following:

game.ServerStorage.StandModule

Could be adjusted to something such as this:

local ServerStorage = game:GetService("ServerStorage")
local StandModule = require(ServerStorage.StandModule) -- Accesses the table that is returned from the ModuleScript, which contains the function you're trying to call

StandModule:GiveStand(parameters) -- Calls the function inside of the ModuleScript

Resources

ModuleScript Documentation

ModuleScripts Article

Intro To ModuleScripts

Creating with ModuleScripts

oh i forgot the require lol thanks

1 Like