Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My one script can't load commands from another specific script, any idea why?

I keep getting this weird error, and I have no idea how to fix it.

I tried to require my script (PlayerPasses.lua) from (GetPlayerPasses.lua) but didn't work either.

Is there a kind soul who might have an idea of ??what it may be I am doing wrong?

Type: RemoteFunction

/ReplicatedStorage/Mads/RemoteFunctions/GetPlayerPasses

Type: Script

/ServerScriptService/Mads/GetPlayerPasses

local replicatedStorage = game:GetService("ReplicatedStorage")
local serverScriptService = game:GetService("ServerScriptService")

local getPlayerPasses = replicatedStorage.Mads.RemoteFunctions.GetPlayerPasses
local path = script.Parent
local playerPasses = path:WaitForChild("PlayerPasses")
print(playerPasses)

function GetList(player)
	playerPasses:CreatePlayerData(player)
	return playerPasses:GetPlayerData(player)
end

getPlayerPasses.OnServerInvoke = GetList

Type: Script

/ServerScriptService/Mads/PlayerPasses

local playerPassesObject = {}
playerPassesObject.__index = playerPassesObject

local playerPasses = {}

function playerPassesObject:CreatePlayerData(player)
	if not (playerPasses[player.UserId]) then 
		playerPasses[player.UserId] = {}	
	end
end

function playerPassesObject:UpdatePlayer(player, gamePass)
	self:CreatePlayerData(player)
	
	table.insert(playerPasses[player.UserId], gamePass)
end

function playerPassesObject:GetPlayerData(player)
	return playerPasses[player.UserId]	
end

return playerPassesObject

Type: LocalScript

/StarterPlayer/StarterPlayerScripts/GetPlayerPasses

local replicatedStorage = game:GetService("ReplicatedStorage")

local getPlayerPasses = replicatedStorage.Mads.RemoteFunctions:WaitForChild("GetPlayerPasses")

local playerPasses = getPlayerPasses:InvokeServer()
print(playerPasses)

You can find the log and errors here.

Thanks in advance!

1 answer

✓ Accepted answer

The problem is

It's a Script /ServerScriptService/Mads/PlayerPasses

If I'm correct, you can't require scripts and you can only require ModuleScripts

which means you have to create a ModuleScript inside ServerStorage or just anywhere you like - I prefer ServerStorage

Else everything looks correct and instead of

local path = script.Parent
local playerPasses = path:WaitForChild("PlayerPasses") 
print(playerPasses)

you should do

local path = serverStorage.Mads
local playerPasses = require(path:WaitForChild("PlayerPasses"))
print(playerPasses)

This discussion is preserved as it was. New answers, comments, and votes are closed.