Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Cikeruw 14
2 years 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
        player.leaderstats.Jenny.Value += 5
        --end

end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years 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
                player.leaderstats.Jenny.Value += 5
            end
        end
    end
end)
Ad

Answer this question