Hey!
So, I was trying to use a require() method to get some modules from a server script located in ServerScriptService. But for some reason the script where the method is located (which is in workspace in a proximity prompt) just can’t find the modules not only in that script, but entirely in ServerScriptService! But I’ve tried to just make a variable of these scripts in SSS and it worked, the script found the modules, but cannot require() them.
It is not a client script, the modules are used by other systems and the game runs perfectly fine, fortunately. How do I get the modules?
If you need to take a look at explorer / the script tell me, I’d appreciate any help provided!
you don’t do that
workspace is client-sided space, and it has unrestricted access to ReplicatedStorage; require from there
store only modules and scripts in ServerScriptService which are meant for “backend” only
The workspace can absolutely access the ServerScriptService, no idea what people are talking about but that should not be the reason why it doesn’t work. Would you be able to show the code how you are requiring the module in the workspace?
Quite the opposite, workspace is, by default, a server script container and will only run normal scripts and scripts with their RunContext set to client. Server scripts also have access to anything server-sided, as long as they are able to run.
I really don’t leave scripts on the workspace and have always assumed the workspace is client-side. Apparently, it’s a bit more complicated than that. Everything has always worked out as expected, so this is a bit of a shock.
local UpgradePad = script.Parent
local Prompt = UpgradePad.Attachment:WaitForChild("ProximityPrompt")
local Players = game:GetService("Players")
local sss = game:GetService("ServerScriptService")
task.wait(1)
local datascript = sss.ServerLoader.Modules:WaitForChild("PlayerDataModule")
local aggregationscript = sss.ServerLoader.Modules:WaitForChild("DataAggregation")
local PlayerDataModule = require(datascript)
local DataAggregation = require(aggregationscript)
local dataReplica = DataAggregation.WaitForReplica()
local PlotTemplate = UpgradePad.Parent
local FloorsFolder = PlotTemplate:WaitForChild("Floors")
local TweenService = game:GetService("TweenService")
local playerCooldowns = {}
-- SETTINGS
local BASE_COST = 100000 -- 100k
local COST_MULTIPLIER = 10
-- Function to calculate cost
local function getUpgradeCost(level)
return BASE_COST * (COST_MULTIPLIER ^ level)
end
local function updatePrompt(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local level = leaderstats:FindFirstChild("Level")
if not level then return end
local cost = getUpgradeCost(level.Value)
Prompt.ObjectText = "Upgrade Plot"
Prompt.ActionText = "$"..cost
end
-- Reveal floor
local function revealFloor(floorModel)
for _, part in ipairs(floorModel:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1
part.CanCollide = false
local tween = TweenService:Create(part, TweenInfo.new(1), {Transparency = 0})
part.CanCollide = true
tween:Play()
end
end
end
-- Upgrade function
local function unlockNextFloor(player)
if playerCooldowns[player] then return end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local level = leaderstats:FindFirstChild("Level")
local cash = leaderstats:FindFirstChild("Cash")
if not level or not cash then return end
local nextLevel = level.Value + 1
local cost = getUpgradeCost(level.Value)
--Check money
local playerData = PlayerDataModule.WaitFor(player)
if dataReplica.Data.Cash < cost then
print("Not enough money!")
return
end
local nextFloor = FloorsFolder:FindFirstChild("Floor"..nextLevel)
if not nextFloor then return end
-- Deduct money
playerData:Set({"Cash"}, playerData.Profile.Data.Cash - cost)
playerCooldowns[player] = true
revealFloor(nextFloor)
level.Value = nextLevel
task.wait(1)
playerCooldowns[player] = nil
end
-- When player activates prompt
Prompt.Triggered:Connect(function(player)
unlockNextFloor(player)
end)
It just outputs an error as if it’s a client script, but it’s not. idk maybe the ServerScriptService is just read-only for other scripts???
Also I noticed that it doesn’t print an InfiniteYield warning right now for “PlayerDataModule”, which I require first, when I didn’t wrap into :waitForChild() it printed 2 errors for PlayerDataModule and for DataAggregation.
@Fietowski sadly it isn’t a joke for me atleast : (
If I could do that, but I need the modules which are the part of the backend system and they are already linked together so it’ll be impossible for me to transfer them to ReplicatedStorage.