Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can i please have help makeing a button wen clicked it spawns a npc?

i tried to make a stand and stuff i need help with a code please

6 comments

0

You need to try your self first and show us how you did it

0

Is... Is that a request?

0

Please, isn't a request site. If you want help put your script with your question.

0

i tryed i just cant find a way yo make it

0

to*

0

i tryed to make it im just so new ro lua

1 answer

Ok, in order to do this you are gonna use a RemoteEvent. In the localscript inside of the textbutton to spawn the NPC put the following:

local rem = game:GetService('ReplicatedStorage'):WaitForChild('SpawnNPC') --This gets our remote event

script.Parent.MouseButton1Click:connect(function()
	rem:FireServer() --Fires it
end)

now in the ServerScriptService, put the following in a script:

local remote = game:GetService('ReplicatedStorage'):WaitForChild('SpawnNPC')

remote.OnServerEvent:connect(function()
	local npc = game.ReplicatedStorage:WaitForChild('Soldier') --Our NPC in this case is a soldier
	npc:Clone().Parent = workspace --Spawns the NPC into workspace
end)

I hope this helps you out, but please remember that this isn't a request site and the next time you have a question put in your code so we can help you out

1 comment

0

Maybe use the InsertService to insert a NPC into the game?

This discussion is preserved as it was. New answers, comments, and votes are closed.