currently I have a script that’ll pick a random weapon, clone it, and put it inside the player’s character. I also have a viewmodel script working along side this
everything works perfectly fine! until I load the player character… the way my viewmodel script works is it checks the player for a tool being added, and then gets the tool’s children, and making it transparent. this doesn’t work when the player is loaded. the tool is cloned and forced into the character, but it hasn’t fully loaded on the client, thus it does not change any of the parts.
so in full I just need to know how I could wait for the tool to fully load before I make it transparent for the localplr, or maybe I should be doing this differently
if not game:IsLoaded() then
game.Loaded:Wait()
end
Course this would only work in certain cases, depending on where your script is located and where the tools are located.
If that doesn’t work, you could try looping through it’s original parent of the tool and use :WaitForChild().
You could use the ChildAdded event to detect when they’re done loading:
local tool = script.Parent
local function onChildAdded(instance: Instance)
if instance:IsA("BasePart") then
instance.Transparency = 1
end
end
tool.ChildAdded:Connect(onChildAdded)
for _, instance in tool:GetChildren() do onChildAdded(instance) end
You could also use DescendantAdded if you’d like to detect parts that are children of other parts which are inside of your Tool:
local tool = script.Parent
local function onDescendantAdded(instance: Instance)
if instance:IsA("BasePart") then
instance.Transparency = 1
end
end
tool.DescendantAdded:Connect(onDescendantAdded)
for _, instance in tool:GetDescendants() do onDescendantAdded(instance) end
Don’t forget to disconnect the connection once it’s no longer required, though