How can I only spawn the NPC for the player doing the quest?

Hey everyone! How can I only spawn the “Bandit” or NPC for the player doing the quest without using any localscripts? Here is my script:

local ServerStorage = game:GetService("ServerStorage")
local QuestNPC = game.Workspace.QuestNPCs:WaitForChild("John")

local QuestEvent = game.ServerStorage.QuestEvents:WaitForChild("KillTheBanditEvent")
local EnemyNPC = game.ServerStorage.Enemies.Bandit:Clone()

local SoundService = game:GetService("SoundService")

QuestNPC.QuestPrompt.Triggered:Connect(function(player)
	local QuestGui = player.PlayerGui.QuestGui
	QuestGui.QuestFrame.Yes.Visible = true
	QuestGui.QuestFrame.QuestInfo.Text = "A bandit is coming to take all our Coins! He has defeated all our soldiers, do you think you can defeat him?"
	QuestGui.QuestFrame.Reward.Text = "Reward: 100 Coins, 95 Exp"
	QuestGui.QuestFrame.Visible = true

	QuestEvent:FireClient(player, "UIDisable")

	QuestGui.QuestFrame.Yes.MouseButton1Click:Connect(function()
		if player:FindFirstChild("QuestInProgress") then
			return
		end

		local QuestInProgress = Instance.new("StringValue", player)
		QuestInProgress.Name = "QuestInProgress"

		QuestGui.QuestFrame.Visible = false
		QuestEvent:FireClient(player, "UIDisable")

		local EnemyNPCClone = EnemyNPC:Clone()
		EnemyNPCClone.Name = player.Name.."Bandit"

		QuestGui.CurrentQuestFrame.CurrentQuestTextLabel.Text = "Defeat the Bandit"
		QuestGui.CurrentQuestFrame.Visible = true
		task.wait(1.5)

		EnemyNPCClone:PivotTo(QuestNPC.HumanoidRootPart.CFrame * CFrame.new(-1, -1, 20))
		EnemyNPCClone.Parent = workspace.Enemies

		QuestGui.CurrentQuestFrame.CurrentQuestTextLabel.Text = "The Bandit has come, attack him!!!"

		EnemyNPCClone.Humanoid.Died:Connect(function()
			EnemyNPCClone:Destroy()

			if not workspace.Enemies:FindFirstChild(player.Name.."Bandit") then
				local leaderstats = player:FindFirstChild("leaderstats")
				leaderstats.Coins.Value += 100
				QuestGui.CurrentQuestFrame.CurrentQuestTextLabel.Text = "You have defeated the Bandit, Good job!"
				QuestGui.Parent.QuestCompletedGui.CompletedFrame.Reward.Text = "Coins: 100, Exp: 95"
				QuestGui.Parent.QuestCompletedGui.CompletedFrame.QuestName.Text = 'The quest "Fight The Bandit" is completed! Tip: Help Jack, who is by the trees.'

				local EXP = player.Stats.Exp
				EXP.Value = EXP.Value + 95

				wait(0.5)
				local QuestCompletedSound = SoundService:WaitForChild("QuestCompletedSound"):Clone()
				QuestCompletedSound.Parent = player:WaitForChild("PlayerGui")
				QuestCompletedSound:Play()
				QuestGui.Parent.QuestCompletedGui.Enabled = true
				wait(5.5)

				QuestGui.CurrentQuestFrame.CurrentQuestTextLabel.Text = ""
				QuestGui.CurrentQuestFrame.Visible = false
				QuestGui.Parent.QuestCompletedGui.Enabled = false

				QuestInProgress:Destroy()

				wait(0.5)
				QuestEvent:FireClient(player, "UIEnable")
			end
		end)
	end)

	QuestGui.QuestFrame.Bye.MouseButton1Click:Connect(function()
		QuestGui.QuestFrame.Visible = false
		QuestEvent:FireClient(player, "UIEnable")
	end)
end)

I guess what you could attempt is send a remote event to all clients, the client then simply destroys the NPC.

The only way (And the easiest way ) would just be to spawn it on a local script though.

is there any specific reason why you dont want to?

No, I was just hoping I could do it through a server script. If the absolute easiest way to do it is through a local script, I have no idea how, yes I’m new to lua. Could you please give me some code for it?

1 Like

Mabye you could look up how to use remote events? i dont really feel like making a whole script for this right now :sob:

1 Like

Haha, I know how to use remote events. I tried fixing it earlier in the day, but failed I don’t know why, but the NPC successfully spawned in only for the local player and it did everything correct. Except that I couldn’t deal damage to it :frowning: I still don’t know how to fix it

1 Like

I dont know either… :confused: Sorry :sob:

1 Like