#that lil script is does not work

1 messages · Page 1 of 1 (latest)

mighty bane
#
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")

--local Remotes = RS:WaitForChild("Remotes")

function Player_Character_Spawn(Player: Player)
--    repeat task.wait() until game.Loaded --Player:GetAttribute("Loaded") == true
    Player:LoadCharacterAsync()
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local Humanoid = Character:WaitForChild("Humanoid")

    local Accessory_Folder = Instance.new("Folder");Accessory_Folder.Parent = Character;Accessory_Folder.Name = "Accessory_Floder"
    Player.CharacterAdded:Wait()
    for i, v in pairs(Character:GetChildren()) do
        if v:IsA("Accessory") then

            local handle = v:FindFirstChild("Handle")
            if handle then
                local copy = handle:Clone()
                copy.Parent = Accessory_Folder
                copy.Massless = false
                copy.CanCollide = false
                copy.CollisionGroup = "Nope"

                if handle.TextureID ~= "" then
                    copy:SetAttribute("baseTexture", handle.TextureID)
                end

                v:Destroy()
            end

        elseif v:IsA("Script") and v.Name == "Health" then
            v:Destroy()
        elseif v:IsA("BasePart") then
            v.CollisionGroup = "Player"
        --elseif v:IsA("Humanoid") then
        --    v:Destroy()
--            local New_Humanoid = SS.Assets.Players:FindFirstChild("Humanoid"):Clone();New_Humanoid.Parent = Character
        end
    end


end

local function playerAdded(Player: Player)
    Player_Character_Spawn(Player)
end

for i, Player in Players:GetPlayers() do
    playerAdded(Player)
end

Players.PlayerAdded:Connect(playerAdded)

Accessories part don't go to folder

clever horizon
#

what doesn't work

vale pewter
#

idk ask ai

steel mortar
#

are there any errors? If not, at what line does the code stop working?

mighty bane
mighty bane
steel mortar
#

then we can diagnose it

fluid parcel
#

also hi zimkek

mighty bane
#

proble is what folder is makeing but Accessories don't go to this folder

#

test it

fluid parcel
#
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

-- Handles a single accessory
local function HandleAccessory(accessory: Accessory, accessoryFolder: Folder)
    local handle = accessory:FindFirstChild("Handle")
    if not handle then
        return
    end

    local handleCopy = handle:Clone()
    handleCopy.Parent = accessoryFolder
    handleCopy.Massless = false
    handleCopy.CanCollide = false
    handleCopy.CollisionGroup = "Nope"

    if handle.TextureID ~= "" then
        handleCopy:SetAttribute("baseTexture", handle.TextureID)
    end

    accessory:Destroy()
end

-- Processes all character children
local function ProcessCharacter(character: Model)
    local accessoryFolder = Instance.new("Folder")
    accessoryFolder.Name = "Accessory_Floder"
    accessoryFolder.Parent = character

    for _, child in character:GetChildren() do
        if child:IsA("Accessory") then
            HandleAccessory(child, accessoryFolder)

        elseif child:IsA("Script") and child.Name == "Health" then
            child:Destroy()

        elseif child:IsA("BasePart") then
            child.CollisionGroup = "Player"
        end
    end
end

-- Main spawn handler
local function PlayerCharacterSpawn(player: Player)
    player:LoadCharacterAsync()

    local character = player.Character or player.CharacterAdded:Wait()
    character:WaitForChild("Humanoid")

    -- Preserved original timing behavior
    player.CharacterAdded:Wait()

    ProcessCharacter(character)
end

-- Player lifecycle
local function OnPlayerAdded(player: Player)
    PlayerCharacterSpawn(player)
end

-- Handle existing players
for _, player in Players:GetPlayers() do
    OnPlayerAdded(player)
end

-- Handle new players
Players.PlayerAdded:Connect(OnPlayerAdded)
#

this is a more workable form

steel mortar
#
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")

--local Remotes = RS:WaitForChild("Remotes")

function Player_Character_Spawn(Player: Player)
    --    repeat task.wait() until game.Loaded --Player:GetAttribute("Loaded") == true
    Player:LoadCharacterAsync()
    local Character = Player.Character

    local Accessory_Folder = Instance.new("Folder")
    ;Accessory_Folder.Parent = Character;Accessory_Folder.Name = "Accessory_Floder"
    
    for i, v in pairs(Character:GetChildren()) do
        if v:IsA("Accessory") then
            print("Got accessory")
            local handle = v:FindFirstChild("Handle")
            if handle then
                print("Got handle")
                local copy = handle:Clone()
                copy.Parent = Accessory_Folder
                copy.Massless = false
                copy.CanCollide = false
                copy.CollisionGroup = "Nope"
                
                print("Added to folder")
                if handle.TextureID ~= "" then
                    copy:SetAttribute("baseTexture", handle.TextureID)
                    print("Attribute set")
                end

                v:Destroy()
            end

        elseif v:IsA("Script") and v.Name == "Health" then
            v:Destroy()
        elseif v:IsA("BasePart") then
            v.CollisionGroup = "Player"
            --elseif v:IsA("Humanoid") then
            --    v:Destroy()
            --            local New_Humanoid = SS.Assets.Players:FindFirstChild("Humanoid"):Clone();New_Humanoid.Parent = Character
        end
    end


end

local function playerAdded(Player: Player)
    Player_Character_Spawn(Player)
end

for i, Player in Players:GetPlayers() do
    playerAdded(Player)
end

Players.PlayerAdded:Connect(playerAdded)
#

Just tested this a bunch in studio and it works

steel mortar
#

the issue was adding

local Character = Player.Character or Player.CharacterAdded:Wait()

Player.CharacterAdded:Wait()

you can't really call CharacterAdded:Wait() on the server at least from what i've seen and i also removed the waiting for humanoid since there was no references to it

#

but you can access the humanoid still if you need it

mighty bane
steel mortar
mighty bane
steel mortar
mighty bane
#

huuuhhhhh

#

wth it not work

#

in my game

mighty bane
steel mortar
# mighty bane

did you make sure to disable the characterautoloads in the Players tab?

#

since you have the LoadAsync in the script

mighty bane
#

but i make that now3

#

and it still don't work

#

just folder but it empty

steel mortar
steel mortar
# mighty bane that not work too
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")

--local Remotes = RS:WaitForChild("Remotes")

function Player_Character_Spawn(Character : Model)
    --    repeat task.wait() until game.Loaded --Player:GetAttribute("Loaded") == true
    local Accessory_Folder = Instance.new("Folder")
    ;Accessory_Folder.Parent = Character;Accessory_Folder.Name = "Accessory_Floder"

    for i, v in pairs(Character:GetChildren()) do
        if v:IsA("Accessory") then
            print("Got accessory")
            local handle = v:FindFirstChild("Handle")
            if handle then
                print("Got handle")
                local copy = handle:Clone()
                copy.Parent = Accessory_Folder
                copy.Massless = false
                copy.CanCollide = false
                copy.CollisionGroup = "Nope"

                print("Added to folder")
                if handle.TextureID ~= "" then
                    copy:SetAttribute("baseTexture", handle.TextureID)
                    print("Attribute set")
                end

                v:Destroy()
            end

        elseif v:IsA("Script") and v.Name == "Health" then
            v:Destroy()
        elseif v:IsA("BasePart") then
            v.CollisionGroup = "Player"
            --elseif v:IsA("Humanoid") then
            --    v:Destroy()
            --            local New_Humanoid = SS.Assets.Players:FindFirstChild("Humanoid"):Clone();New_Humanoid.Parent = Character
        end
    end


end

local function playerAdded(Player: Player)
    Player_Character_Spawn(Player.Character)
end

for i, Player in Players:GetPlayers() do
    playerAdded(Player)
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        Player_Character_Spawn(character)
    end)
end)

New script that still works fine but removed the LoadCharacterAsync and enabled characterautoloads in players

#

if you still need the player in the function you can get them from their character

mighty bane
#

it still don't work

mighty bane
#

bro i thinks this can help me

CharacterAppearanceLoaded

steel mortar
#

which i use a lot as well