I wish to add 5 exp to my exp bar once the npc is killed. this is the script to change the text when exp is received:
local player = game.Players.LocalPlayer local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp") local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
while true do wait() script.Parent.Text = "EXP: " .. exp.Value .. "/" .. axp.Value end And this is the script for the bar changing once the exp is gained:
local player = game.Players.LocalPlayer local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp") local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
while true do wait() local expBarSize = (exp.Value/axp.Value) - 0.02 if exp.Value == 0 then expBarSize = 0 script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Linear", 0.25) else script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Linear", 0.25) end end
and this is the script for leveling up once exp reaches a certain amount:
--GetLevel Script (Local Script) local player = game.Players.LocalPlayer local level = player:WaitForChild("leaderstats"):WaitForChild("Level")
script.Parent.Text = "Current Level: " .. level.Value
level.Changed:Connect(function(value) script.Parent.Text = "Current Level: " .. value end)
oh and I may of also made a mistake on which one functions which because i forgot to rename them once i made them, Sorry!
I think this answers what you are asking. You will need to figure out the player who killed the NPC and assign it to the playerWhoKilled variable
--This would go in the script that handles the killing of the NPC local playerWhoKilled --Player who killed the NPC. local xpDrop = 5 playerWhoKilled:WaitForChild("leaderstats"):WaitForChild("Exp").Value += xpDrop