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

Adding tables or items to module scripts, from another script?

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage.Remotes:WaitForChild("grabRemote")
local closestCrystal = script.Parent
remote.OnServerEvent:Connect(function(player)
	local playername = player.Name
	local Character = player.Character
	if (closestCrystal.position - Character.HumanoidRootPart.Position).magnitude < 15 then
		if closestCrystal.grabbable.Value == true then
			local playerinventory = require(game.Players[playername].Inventory.Inventory)
			 if table.find(playerinventory, "GreenKyber" ) == nil then
				local GreenKyber = {1}
				table.insert(playerinventory, #playerinventory + 1 or 1 , GreenKyber)
				end
			end
		end
	end)

This is my first inventory system, and I'm attempting to add an item to the players inventory once they fire a remote. However when I do this it doesn't show an output, which does include errors, succses ect.

1 comment

0

well i don't now

1 answer

Not exactly why this does not work. However, try these:

  1. Use a capital 'M' for Magnitude instead of magnitude

  2. "GreenKyber" is most likely not being found because you insert {1} into the module script, not "GreenKyber". So try inserting "GreenKyber" instead of {1}

  3. Remove the or 1 in your table.insert

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