0

# How do I make it so only the person that finished the quest gets money?

Cikeruw 14
16 days ago

There is this script that is for a quest where you face a villain. But when you get the quest it will notify the server. But when the npc dies everyone who is doing the quest gets money how do I fix this.

local NPC = game.Workspace["NPC That Follows You"]
game.ReplicatedStorage.fightingquest.OnServerEvent:Connect(function(player)
while true do
wait()
if NPC.Humanoid.Health <= 0 then
break
end
end
--end

end)


0
Edited 15 days ago

Instead of looping until the npc dies, log the damage done to the npc for each player and if they did enough damage, award the player. This way, you can easily check whether the player contributed or not and you can check when the npc dies without using a remote.

example script, not made to work.

local DAMAGE_VALUES = {}
local MINIMUM_DAMAGE_REQUIRED  = 1
local NPC = game.Workspace["NPC That Follows You"]
-- a way to detect when the npc dies
NPC.Humanoid.Died:Connect(function()
for i,v in pairs(DAMAGE_VALUES) do
-- if the player did enough damage
if v.DAMAGE_DONE >= MINIMUM_DAMAGE_REQUIRED then
local player = v.PLAYER_WHO_DAMAGED
-- make sure player has correct quest
if player.CURRENT_QUEST == "KILL THE NPC" then