I tried many scripts, I searched on YouTube too. I couldn't find a script that makes a npc appear for a while then disappears. Is there anyway I can get help?
How do I make a touch brick that make npc appear and disappear after awhile?
2 answers
Put the NPC in storage and then call for it to be :cloned() to workspace by a script which detects when a block it touched :) then wait for a while the :destroy() it :)
If you wanted to make an NPC, for example, appear for maybe 5 seconds after a brick is touched we could do the following:
-- By using the RBXScriptSignal, or event, Touched, the script will detect when a block is touched
game.Workspace.OurBrick.Touched:Connect(function
end)
Now, let's set up a few functions when the event fires
game.Workspace.OurBrick.Touched:Connect(function
-- This function makes the NPC appear (or change position)
local function npcAppear()
local npc = game.Workspace.NPC
local appearPart = game.Workspace.appearPart -- This is the block that the NPC will teleport to
npc:SetPrimaryPartCFrame(appearPart.CFrame) -- This will make the NPC teleport to the part
end
-- This function will make the NPC disappear
local function npcDisappear()
local npc = game.Workspace.NPC
local disappearPart = game.Workspace.disappearPart
npc:SetPrimaryPartCFrame(disappearPart.CFrame) -- The part it positions to should be in a place the player cannot see
end
end)
So now that we have set up our functions to make the NPC appear/disappear, let's use them
game.Workspace.OurBrick.Touched:Connect(function
local function npcAppear()
local npc = game.Workspace.NPC
local appearPart = game.Workspace.appearPart
npc:SetPrimaryPartCFrame(appearPart.CFrame)
end
local function npcDisappear()
local npc = game.Workspace.NPC
local disappearPart = game.Workspace.disappearPart
npc:SetPrimaryPartCFrame(disappearPart.CFrame)
-- Now we will use our functions and make the NPC appear and then disappear after 5 seconds
npcAppear()
wait(5)
npcDisappear()
end
end)
So, to recap what we just talked about: We set up a connection when the .Touched event is fired. Inside the connection, we set up two functions, one to make the NPC appear and one to make it disappear. Inside these functions we used :SetPrimaryPartCFrame so that it would teleport the entire NPC and not just one part. Once we set up the functions, we used them to make the NPC appear for 5 seconds then disappear. I hope this helped you!
2 comments
So how about the npc? Do we put it somewhere?
You would put it in the workspace, or you could put it in ReplicatedStorage then clone it into workspace when it is needed. If you go down this route, go ahead and destroy the NPC instead of using SetPrimaryPartCFrame to send it away
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
k but what kind of storage