Help to make please

Hello, I made a quest and I wanted you to be given a skill after completing the quest, and not immediately here’s the script that the NPC gives

 local speeches = require(game.ServerStorage.questsTalks)
 local qr = require(game.ServerStorage["quests&rewards"])
 local MarketPlaceService = game:GetService("MarketplaceService")


 local completedText = qr.doneText

 local goUp = qr.goUpBy

 local strength
 local plrsGui
 local endurance
 local pyschic

local questInfo
local targetStat
local targetVal

local gamepassId = 224551349

--hasInvisiblity

local function ownsgamepass(userId, gamepassId)
 local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, userId, gamepassId)
 if not s then
 	res = false
 end
 return res
end

local function change(questNum)
 if questNum == 1 then
 	targetStat.Value = "Strength"
 	targetVal.Value = 10
 elseif questNum == 2 then
 	targetStat.Value = "Endurance"
 	targetVal.Value = 10
 elseif questNum == 3 then
 	targetStat.Value = "Psp"
 	targetVal.Value = 10
 elseif questNum == 4 then
 	targetStat.Value = "Psp"
 	targetVal.Value = 100
 elseif questNum == 5 then
 	targetStat.Value = "Strength"
 	targetVal.Value = 100
 elseif questNum == 6 then
 	targetStat.Value = "Psp"
 	targetVal.Value = 500
 elseif questNum == 7 then
 	targetStat.Value = "Psp"
 	targetVal.Value = 1000
 elseif questNum == 8 then
 	targetStat.Value = "Psp"
 	targetVal.Value = 6000
 end
end

local function setPowerValue(questNum, player)
 if questNum == 4 then
 	player:FindFirstChild("Powers").hasAura.Value = true
elseif questNum == 5 then
 	player:FindFirstChild("Powers").hasEnergyPunch.Value = true
elseif questNum == 6 then
 	player:FindFirstChild("Powers").hasInvisiblity.Value = true
elseif questNum == 7 then
 	player:FindFirstChild("Powers").hasFly.Value = true
end
end

invisWall.Touched:Connect(function(hit)
 if game.Players:GetPlayerFromCharacter(hit.Parent) then
 	local player = game.Players:FindFirstChild(hit.Parent.Name)
 	local userId = player.UserId
 	local has2x = ownsgamepass(userId, gamepassId)
 	local questNum = player:WaitForChild("questNum")
 	strength = player.Strength
 	endurance = player.Endurance
 	pyschic = player.Psp
 	
 	-- Quest Stuff
 	questInfo = player.QuestInfo
 	targetStat = questInfo.Stat
 	targetVal = questInfo.Value
 	----------------------------
 	
 	local hasClickedQuest = player.hasClickedQuest

 	if player.PlayerGui:FindFirstChild("QuestGui") then
 		plrsGui = player.PlayerGui.QuestGui
 		game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 		plrsGui.speechFrame.speech.Selectable = true
 		
 		if questNum.Value == 0 then
 			questNum.Value = 1
 		end

 		if questNum.Value == 1 then
 			plrsGui.speechFrame.speech.Text = speeches.text1
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 2 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text2
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 3 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text3
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 4 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text4
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 5 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text5
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 6 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text6
 			change(questNum.Value)
 			hasClickedQuest.Value = false	
 		elseif questNum.Value == 7 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text7
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		elseif questNum.Value == 8 and plrsGui:WaitForChild("speechFrame").speech.Text == "Great Job Completing Your Quest, Here Is Your Reward!" and hasClickedQuest.Value == true then
 			game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 			plrsGui.speechFrame.speech.Text = speeches.text8
 			change(questNum.Value)
 			hasClickedQuest.Value = false
 		end
 	end
 	
 	if player:FindFirstChild(targetStat.Value) then
 		if (player:FindFirstChild(targetStat.Value).Value > targetVal.Value)==false then
 		game.ReplicatedStorage.showQ:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
 		plrsGui.speechFrame.speech.Selectable = true
 		plrsGui:WaitForChild("speechFrame").speech.Text = completedText
 		if has2x then	
 		local x2 = questNum.Value*2
 			player.Coins.Value += qr["done"..questNum.Value.."coins"] * 2
 		else 
 			player.Coins.Value += qr["done"..questNum.Value.."coins"] 
 		end
 		setPowerValue(questNum.Value, player)
 		questNum.Value  += 1
 		script.Disabled = true
 		wait(0.05)
 		script.Disabled = false
 		plrsGui.Frame.barFrame.bar.Size = UDim2.new(0.018, 0, 1, 0)
 		change(questNum.Value)
 		if player:FindFirstChild(targetStat.Value) then
 		plrsGui.Frame.barFrame.Percent.Text = player:FindFirstChild(targetStat.Value).Value.."/"..targetVal.Value
 		end
 	end
 end
   end
3 Likes

I will be glad to receive any help, this script NPC task

1 Like

himselfThis script is responsible for the quest character that gives quests

1 Like

help pls guys to make a skill so that after completing the quest, it will give

i’m not really sure what’s going on in your code (you need to work on shortening it)
instead of checking each QuestId you could get the speech text using the QuestId

-- Rename "questNum" -> "QuestId"
local RS = game:GetService("ReplicatedStorage")

if Player.PlayerGui:FindFirstChild("QuestGui") then
	plrsGui = Player.PlayerGui.QuestGui
	RS.showQ:FireClient(Player)
	plrsGui.speechFrame.speech.Selectable = true

	if plrsGui:WaitForChild("speechFrame").speech.Text == QuestCompletionText and hasClickedQuest.Value then
		RS.showQ:FireClient(Player)
	end
	
	plrsGui.speechFrame.speech.Text = speeches["text".. QuestId]
	UpdateRequirement(QuestId)
	hasClickedQuest.Value = false
end

you could also shorten your “change” function by creating a dictionary

-- I'm assuming these are requirements ("Change" isn't very informative)
local Quests = {
	[1] = {["Stat"] = "Strength", ["Requirement"] = 10};
	[2] = {["Stat"] = "Endurance", ["Requirement"] = 10};
	[3] = {["Stat"] = "Psp", ["Requirement"] = 10};
	[4] = {["Stat"] = "Psp", ["Requirement"] = 100};
	[5] = {["Stat"] = "Strength", ["Requirement"] = 100};
	[6] = {["Stat"] = "Psp", ["Requirement"] = 500};
	[7] = {["Stat"] = "Psp", ["Requirement"] = 1000};
	[8] = {["Stat"] = "Psp", ["Requirement"] = 6000};
}

local function UpdateRequirement(QuestId)
	local Quest = Quests[QuestId]
	assert(Quest, "Attempted to update quest requirement as nil")
	targetStat.Value = Quest.Stat
	targetVal.Value = Quest.Requirement
end

-- Could do the same for setPowerValue()

Thank you very much for your help, but how do you make sure that after completing quest 4 you are given an energy blow

1 Like

You can make an IntValue.

IntValue is the amount of quests completed.

lets say the name of the IntValue is “Quests” and its in the leaderstats.

local Quests = game.Players.LocalPlayer.leaderstats.Quests

Quests.Changed:Connect(function()
   if Quests.Value >= 4 then  -- change 4 to any amount of quests to complete
             -- add the rewards for the player here
   end
end)
1 Like

May I ask what is this? I get it, but I don’t understand what you mean

dont you want to check if the player has completed 4 quests?

I have a check, but I would like the player to be given an energy hit after completing the quest

this script already checks if the player completed 4 quests, add you rewards line in the script!

local Quests = game.Players.LocalPlayer.leaderstats.Quests

Quests.Changed:Connect(function()
   if Quests.Value >= 4 then  -- change 4 to any amount of quests to complete
          -- add the energy for the player here
   end
end)
1 Like

you may need to make a leaderboard for this script, and add “Quests”

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.