Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I insert my model with a module script?

Asked by 7 years ago
--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.

0
Yes, please do add any errors you're getting; adding errors gives people additional insight into what your problem may be. Pyrondon 2089 — 7y
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. cabbler 1942 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
--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

Ad

Answer this question