-
What do you want to achieve?
I want to have a local script get data from a module script function. -
What is the issue?
The module script functions don’t work for local scripts. They only work for server scripts. -
What solutions have you tried so far?
I have tried changing the functions and different scripts, and I have also tried finding devforums about this issue but couldn’t find any that helped.
There is a server script that creates gears in the game and when a player’s mouse hovers on the gear, a selection box appears on the gear for the player if they are close enough (must get the position of the gear), but instead after I create a gear using GearInfo.AddGear(), it only shows up for server scripts, and my local script can’t access it using the functions.
Module script:
local GearAmounts = {
["NormalGearPart"] = 0
}
local GearInfo = {
}
local GInfo = {
}
function GearInfo.AddGear(gearType)
print("creating gear data")
GearAmounts[gearType] += 1
local newName = gearType .. tostring(GearAmounts[gearType])
local newInfo = {
["Health"] = 10,
["Drop"] = "NormalGearItem",
["DropAmt"] = 15,
["Size"] = {},
["Orientation"] = {},
["Position"] = {}
}
GInfo[newName] = newInfo
return newName
end
function GearInfo.GetData(gear, data)
print("fetching gear data")
if data == "All" then
return GInfo[gear.Name]
else
print(GInfo)
return GInfo[gear.Name][data]
end
end
function GearInfo.GetAmounts(gearType)
print("fetching gear amounts")
return GearAmounts[gearType]
end
function GearInfo.UpdateData(gear, data, info)
print("updating gear data")
if data == "All" then
GInfo[gear.Name] = info
else
GInfo[gear.Name][data] = info
end
end
function GearInfo.RemoveGear(gear)
print("removing gear data")
GInfo[gear.Name] = nil
end
return GearInfo
Server script:
local function CreateGear()
coroutine.resume(coroutine.create(function()
local gear = Gears[math.random(1, #Gears)]:Clone()
gear.Parent = gearFolder
gear.Name = GearInfo.AddGear(gear.Name)
GearInfo.UpdateData(gear, "Size", gear.Size)
GearInfo.UpdateData(gear, "Orientation", gear.Orientation)
GearInfo.UpdateData(gear, "Position", gear.Position)
print(gear.Name)
end))
end
player script:
-- Select a gear
mouse.Move:Connect(function()
local target = mouse.Target
if target then
print(target.Name)
if gearFolder:FindFirstChild(target.Name) then
local gearPosition = GearInfo.GetData(target, "Position") -- when it calls on the module script it says trying to access nil, even though the gear exists in the table.
local magnitude = (character.HumanoidRootPart.Position - gearPosition)
if magnitude <= 10 then -- ignore stuff in here
selectionBox.Adornee = target
if pickActivated then
PlrHitGear:FireServer(target, pickActivated)
end
end
end
end
end)