How does a player gain exp when he kills an NPC? Here are the scripts from the weapon and the leaderboard script. Thanks!
Script in workspace:
local levelup = {}
game.Players.PlayerAdded:connect(function(Player)
local stats = Instance.new("IntValue")
local lv = Instance.new("IntValue",stats)
lv.Name = "Lv"
lv.Value = 1
local exp = Instance.new("IntValue",stats)
exp.Name = "EXP"
exp.Value = 0
stats.Parent = Player
stats.Name = "leaderstats"
exp.Changed:connect(function()
if exp.Value >= levelup[lv.Value]then
exp.Value = exp.Value - levelup[lv.Value]
lv.Value = lv.Value + 1
end
end)
end)
Local script in weapon:
local animation = Instance.new('Animation')
local animTrack
local debounce = false
local player = game.Players.LocalPlayer.Character
function onEquip()
script.Parent.Handle.UnsheathSound:Play()
end
function onActivate()
if not debounce then
debounce = true
if player:FindFirstChild('ForceField') then player.ForceField:Destroy() end
animation.AnimationId = "http://www.roblox.com/asset/?id=129967390"
animTrack = player.Humanoid:LoadAnimation(animation)
animTrack:Play()
script.Parent.Handle.SlashSound:Play()
script.Parent.Handle.Script.Disabled = false
wait(0.5)
animTrack:Stop()
script.Parent.Handle.Script.Disabled = true
wait(0.5)
debounce = false
end
end
function onUnequip()
animTrack:Stop()
end
script.Parent.Equipped:connect(onEquip)
script.Parent.Unequipped:connect(onUnequip)
script.Parent.Activated:connect(onActivate)
Script in weapon's handle:
local debounce = false
function onTouched(hit)
if not debounce then
debounce = true
if hit.Parent.Name:sub(1,17) == "AFK Noob Lv 1 HP " then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
wait(0.5)
debounce = false
end
end
end
script.Parent.Touched:connect(onTouched)

1 comment
so the script for the weapon is the thing were killing the npc with right