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)