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

Granting gear to player upon join - how to wait until the player is fully loaded?

Asked by 3 years ago
  1. I successfully step through this method to grant joining players gears.
  2. But I'm guessing the rest of character loading is replacing the backpack, so the player never gets the gear
  3. What's the proper way to run scripts after the basic player backpack setup is done?
local dataSource = require(game.ServerScriptService.BehaviorLogic)

function playerJoined(player)
    local gear = dataSource["GetInfo"](player, "GetGear")
    SetupGear(player, gear)
end

local ins = game:GetService("InsertService")

function SetupGear(player, gear)
    --wait(5) uncommenting this line makes it work
    for _, assetId in ipairs(gear) do

        print("Granting"..tostring(assetId))
        local tool = ins:LoadAsset(assetId):GetChildren()[1]
        print(tool)
        tool.Parent = player.Backpack
    end
end

game.Players.PlayerAdded:Connect(playerJoined)

2 answers

Log in to vote
0
Answered by 3 years ago

Add this line to ensure the character is fully loaded.

player.CharacterAdded:Wait()
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You can use game.Loaded:Wait() to wait until the game is completely loaded, you should put this in a local script, then after that line you can fire a remote event to the server and give them the tool then.

if you want to go with the character, then use repeat wait() until player.Character

Alternatively you can just add a wait(5) or more seconds before you give the tool.

Also the player joined function should be beneath the setup tools function.

Answer this question