Hello,
So i made a gamepass. What the gamepass do is when an enemy npc attack the player the player only get the half of the damage.
Example: A enemy npc hit the player normally the player gets 30 damage but with the gamepass the player only get 15 damage.
Here’s my code:
local npc = script.Parent
local hrpOfNPC = npc:WaitForChild("HumanoidRootPart")
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassId = 20325308
local plrsHit = {}
local maxDistance = math.huge
npc.Humanoid.Touched:Connect(function(touch)
local player = game.Players:GetPlayerFromCharacter(touch.Parent)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
if game.Players:GetPlayerFromCharacter(touch.Parent) and not plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] then
plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] = true
touch.Parent.Humanoid:TakeDamage(15)
wait(1)
plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] = false
end
elseif game.Players:GetPlayerFromCharacter(touch.Parent) and not plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] then
plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] = true
touch.Parent.Humanoid:TakeDamage(30)
wait(1)
plrsHit[game.Players:GetPlayerFromCharacter(touch.Parent)] = false
end
end)
while wait() do
local plrs = game.Players:GetPlayers()
local closestHRP
for i, plr in pairs(plrs) do
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character.Humanoid.Health > 0 then
local hrp = plr.Character.HumanoidRootPart
local distanceBetween = (hrpOfNPC.Position - hrp.Position).Magnitude
if not closestHRP then closestHRP = hrp end
if (hrpOfNPC.Position - closestHRP.Position).Magnitude < distanceBetween then
closestHRP = hrp
end
end
end
if closestHRP and (hrpOfNPC.Position - closestHRP.Position).Magnitude <= maxDistance then npc.Humanoid:MoveTo(closestHRP.Position) end
end