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

Players not receiving tools at random. What am I missing?

Asked by 3 years ago

I have had a persistent bug in my game that I cannot seem to fix. I have a script in ServerScriptService that evaluates a player's rank in the group and assigns them tools accordingly. The problem is that on initial load a large percentage of the time the player does not receive the tools. This appears to be most prevalent when it is the first player in the server.

Upon doing a player reset 100% of the time the player gets the tools as I intend.

I have tried many things including suggestions from this post.

Clearly the issue pertains to the tools or player not loading in fully by the time the script executes. I have tried addressing both scenarios with waitFor commands as shown in the code below.

The only scenario I'm not covering is any wait for the group lookup, however I understand that it pauses the script so I should be covered there. Any help would be greatly appreciated.

game.Players.PlayerAdded:Connect(function(Player)
---- Load all player defaults
    local thisPlayer ={}
    thisPlayer.Name = Player.Name
    thisPlayer.UserId = Player.UserId
    thisPlayer.Rank = Player:GetRankInGroup(settings.groupId)
... more player defaults are loded
... code to loop through rank levels assigning a Boolean on whether or not to assign various tools
... code that fires an event to send some initialization parameters to the client for later use

Player.CharacterAdded:Connect(function(Character)
wait(Character:WaitForChild("HumanoidRootPart"))
local tool = game.ServerStorage:WaitForChild("SpecifiedTool") -- The tool you want to give
local toolCopy = tool:Clone() -- Make a clone of the original tool
toolCopy.Parent = Player.StarterGear
    end)     -- charachterAdded
end) -- playerAdded

1 answer

Log in to vote
0
Answered by 3 years ago

In the event that anyone in the future has this issue, here is the solution.

I did not put a wait check on the StarterGear folder...

local starterGear = Player:WaitForChild("StarterGear")

I was too focused on the player character so the following code does not seem to have been needed and was removed:

Player.CharacterAdded:Connect(function(Character)
wait(Character:WaitForChild("HumanoidRootPart"))
Ad

Answer this question