Help with a Bing AI script

Hey guys, so I generated a roblox script from the bing AI and i’m just checkin’ if this actually works! I need it for a backrooms game that I might end up making minimalistic. I forgot how to put the font for the script so here it is.

local part = script.Parent
local npcSpawned = false
local spawnPart = game.Workspace.Part – Replace “Part” with the name of the part you want the NPC to spawn at

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and not npcSpawned then
local npc = game.ServerStorage.NPC:Clone()
npc.Parent = game.Workspace
npc.HumanoidRootPart.CFrame = spawnPart.CFrame
npcSpawned = true
end
end)

Looks about right, just track when the npc dies to make npcSpawned = false

if you use ctrl+e it will do the format, or if you use ` followed by code then `` (remove the second backtick)

Alright, just about answered my question, thank ye.

Is this alright?

local part = script.Parent
local npcSpawned = false
local spawnPart = game.Workspace.Part – Replace “Part” with the name of the part you want the NPC to spawn at

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and not npcSpawned then
local npc = game.ServerStorage.NPC:Clone()
npc.Parent = game.Workspace
npc.HumanoidRootPart.CFrame = spawnPart.CFrame
npcSpawned = true

    -- Add this line to set npcSpawned to false when the NPC dies
    npc.Humanoid.Died:Connect(function()
        npcSpawned = false
    end)
end

end)

Looks good, all you need to do is set the spawnPart now!

Yup, If I have anymore questions ill reply here!

1 Like