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

How do I insert my model with a module script?

--MainModule
local _M = {}
script.Parent = game.Workspace
function _M.give()
game:GetService("InsertService"):LoadAsset(842321306).Parent = game.Players.Player1.Backpack
end
return _M


--Script
local sword = require(game.Workspace.MainModule)
sword.give()

So what I am trying to do here is insert a sword I made yesterday into a script builder with module scripting I am new to module scripting and I don't fully know what I am doing I was using the wiki but nothing seemed to happen, please can someone explain to me. I didn't know if I needed to add the errors I was getting please tell me if I need to.

2 comments

0

Yes, please do add any errors you're getting; adding errors gives people additional insight into what your problem may be.

0

Like always you can't be sure things instantly load. WaitForChild! Otherwise, I'm pretty sure LoadAsset loads stuff as children of a model? Look into that.

1 answer

--MainModule
local _M = {}
script.Parent = game.Workspace
function _M.give(Player)
game:GetService("InsertService"):LoadAsset(842321306).Parent = Backpack
end
return _M


--Script
local sword = require(game.Workspace.MainModule)
local AllowPlayers = {"Player1","Player2","etc"}

function CheckPlayer(Player)	--Checks if the player is in the list
	for _,p in pairs(AllowPlayers) do
		if p == Player.Name then
			return true
		end
	end
end

game.Players.PlayerAdded:connect(function(Player)
	if CheckPlayer() then
		sword.give(Player.Backback)
	end
end

Personally I'd do this, this allows for multiple players to be given the sword and it activates when a new player is added to Players instead of trying to give the sword straight away when the game starts. Hope this helps Not I wrote this without testing it, it looks like it should work to me but. human arror and whatnot. Somethign like this should definitely work though

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