I was working on a system to store player values such as ‘damage’, ‘defence’, ‘cooldowns’ etc inside a module script to make them changeable and accessible but I encountered an issue. I can’t access multiple module scripts at the same time? When I read browsing the wiki on them I came across this:
Note that the first call to
require
on a ModuleScript will not yield (halt) unless the ModuleScript yields (e.g. callswait
). The current thread that calledrequire
will yield until a ModuleScript returns a value.
I tested this by creating two instances of the following script:
– Local Script (Creates two instances of):
local RemoteEvent = game:GetService("ReplicatedStorage").TestEvent
local function OnInputBegan(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Text says", script.Parent.Text)
if game.Players:FindFirstChild(script.Parent.Text) then
RemoteEvent:FireServer(script.Parent.Text)
end
end
end
UserInputService.InputBegan:connect(function(input, gameProcessedEvent)
OnInputBegan(input, gameProcessedEvent)
end)
– Server Script (Did not create another instance of):
local RemoteEvent = game:GetService("ReplicatedStorage").TestEvent
local req = nil
local function ChangeValue(player, Text)
print(player.Name)
req = require(game.ServerScriptService.AllStats:FindFirstChild(Text))
req.Defence += 10
print(req.Defence)
print("Printed Defence")
req.Damage(Text, 10, 0, nil)
end
RemoteEvent.OnServerEvent:Connect(ChangeValue)
– This is what req.Damage located inside my server script does:
local PlayerValue = {}
PlayerValue.Debuffs = {}
PlayerValue.Buffs = {}
PlayerValue.Damage = 1
PlayerValue.Defence = 10
PlayerValue.Debuffs = {"Test"}
function PlayerValue.Damage(Target, Damage, Modifier, ReceivedFrom)
local ReceivedFrom
local Target = game.Workspace:FindFirstChild(Target)
local Humanoid = Target:FindFirstChild("Humanoid")
if PlayerValue.Defence > 0 then
print("Player defence not depleted")
else
print("Player defence depleted")
end
print("Damage ordered", tostring(Damage))
print()
end
return PlayerValue
And it only ran it once when I pressed F, whereas it should duplicate it and run it twice as I had two versions of the local script. Did I make an error when trying to test to see if I interpreted the developer wiki right or is this how module scripts function and is not circumventible? That’s annoying if so…