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

my exp script doesnt work properly it gives exp to all players?

Asked by 5 years ago
Edited 5 years ago

when i made a working exp script it gives the exp to all players not the player who killed the npc so can someone help me with it to make it gives exp only to the player who killed the npc or the last attacker

this is the script

local zombie = script.Parent

for _, script in pairs(zombie.ModuleScripts:GetChildren()) do if not game.ServerStorage:FindFirstChild(script.Name) then script:Clone().Parent = game.ServerStorage end end

local AI = require(game.ServerStorage.ROBLOX_ZombieAI).new(zombie) local DestroyService = require(game.ServerStorage.ROBLOX_DestroyService)

local function clearParts(parent) for _, part in pairs(parent:GetChildren()) do clearParts(part) end local delay if parent:IsA("Part") then delay = math.random(5,10) else delay = 11 end DestroyService:AddItem(parent, delay) end

zombie.Humanoid.Died:connect(function() AI.Stop() for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Exp.Value = Player.leaderstats.Exp.Value +4 end end math.randomseed(tick()) clearParts(zombie) script.Disabled = true end)

local lastMoan = os.time() math.randomseed(os.time()) while true do local animationTrack = zombie.Humanoid:LoadAnimation(zombie.Animations.Arms) animationTrack:Play() -- local now = os.time() -- if now - lastMoan > 5 then
-- if math.random() > .3 then -- zombie.Moan:Play() ---- print("playing moan") -- lastMoan = now -- end -- end wait(2) end

0
The reason it's giving it to everyone is because you're looping over every player when the zombie dies aipiox123 1 — 5y
0
Dont loop through players. B_rnz 171 — 5y

Answer this question