#Random Npc that spawns, the npc is a friend

1 messages · Page 1 of 1 (latest)

topaz wigeon
#

So i have this code where i want to spawn npcs, and i want them to look the same as a random friend.

while true do
    if Spawned == false then
        Spawned = true
            
        local Dummy = NpcTemplate:Clone()

        local hrp = Dummy:WaitForChild("HumanoidRootPart")
        hrp.CFrame = SpawnPart.CFrame - Vector3.new(0, 30, 0)
        
        Dummy.Parent = Workspace
        
        local UserId = RngClient.SelectRandomUserID(Players:WaitForChild("Teddy_arm"))
        
        local Description = game.Players:GetHumanoidDescriptionFromUserId(UserId)
        Dummy.Humanoid:ApplyDescription(Description)
        
        hrp.CFrame = SpawnPart.CFrame + Vector3.new(0, 2, 0)

        task.spawn(function()
            MoveToTarget(Dummy, EndPart)
        end)
        
        task.wait(SpawnInterval)
    else
        task.wait(.05)
    end
end```
lilac wind
#

have you tried to first spawn a specific friend of yours.

topaz wigeon
lilac wind
#

yea

#

tried that?

#

Make it work first

#

Randomizing is simple.

#

@topaz wigeon Are you done

topaz wigeon
#

it works in studio

#

just not in roblox

lilac wind
#

allow API access in game settings

topaz wigeon
lilac wind
#

allow HTTP requests too

#

thats what permits fetching friends page

topaz wigeon
lilac wind
#

Does the character model has a HRP set as primary part?

lilac wind
#

Can you paste here the line 133 where the error happens

topaz wigeon
lilac wind
#

hey, maybe its bcuz the character is not loaded

#

try using a task.wait(1)

topaz wigeon
#

my profile store is not working

#

magiclly broke

lilac wind
#

not surprising

#

want help fixing it?

topaz wigeon
#

it was working fine

#

now the attributes wont spawn

#

oh wait it fixed now

#

idk what happende there

#

@lilac wind i fixed it, i just added a pcall so it doesnst stop the script and now it spawns

lilac wind
#

igh

#

back to the main issue

#

have u tried the resolve

#

i just suggested

#

also make sure the namings are correct. HumanoidRootPart

#

its case-sensitive

topaz wigeon
#

but erm

#

i got a issue with my profile store

#

wanna help?

lilac wind
#

sure

topaz wigeon
# lilac wind sure

okay so pretty much every time i run the SetValueAtKey function it resets my attribute data to the default

lilac wind
#

The ProfileLoaded logic is resetting the values to default

#

everytime

#

mb it was intentional

#

Bro fix the naming. There are two values in the same scope (doesnt cause a bug but still bad practice)

local function SetValueAtKey(player : Player, key : string, value : any)
    local profile = Profiles[player]
    if not profile then return end
    if not key then return end
    
    profile.Data[key] = value
    
    if key == "Attributes" then
        for id, value in profile.Data.Attributes do
            print(id, value)
            player:SetAttribute(id, value)
        end
    end
end```
#

I can't pinpoint it but its related to the ProfileLoaded() function that defaults the values, in case like the attributes names don't match.

lilac wind
#

mb I won't be able to help with data saving yet. havent tried my hand on it yet