Hey i know This is my 4th or 5th Post Containing scripting support But i am just really new to scripting and ever since i ranked up on the forum i’ve been needing it.
So here it goes again!
Ive been creating a level system And i used this video to make it (Yes it was a tutorial)
Can you Please help me edit this script to make when u kill a npc called deblox (or you can put it as NPC)It will give u Exp to rank up.
I will try to answer as fast as i can. to your messages
Script:
game:GetService("Players").PlayerAdded:Connect(function(player)
if player then
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local statsfolder = Instance.new("Folder")
statsfolder.Name = "stats"
statsfolder.Parent = player
local levelval = Instance.new("IntValue")
levelval.Parent = leaderstats
levelval.Name = "Level"
local exp = Instance.new("IntValue")
exp.Parent = statsfolder
exp.Name = "EXP"
local requiredexp = Instance.new("IntValue")
requiredexp.Parent = statsfolder
requiredexp.Name = "RequiredEXP"
requiredexp.Value = 100
exp.Changed:Connect(function()
if exp.Value >= requiredexp.Value then
levelval.Value = levelval.Value + 1
exp.Value = 0
requiredexp.Value = requiredexp.Value * 2
end
end)
while true do
wait(1)
exp.Value = exp.Value + 10
end
end
end)
For Beginners Use this to help as well
Make it as a script in serverscriptservice and call it
Playeradded then paste it in Watch the Full video I watched to know more becaus ei already wrote too much on this topic.
This part is The part that gives u 10 exp every second
while true do
wait(1)
exp.Value = exp.Value + 10
end
I’m assuming your enemy is probably a character model (that you would control). In your enemy, they have an object called “Humanoid.” Whatever tool you are using to do damage (assuming you do something like health -= amount), you can check if the health subtracted by the amount will be less than or equal to 0. From there, that tool you are using probably has a parent (being your character model) that is attached to that tool. You can reference to your character and use the method GetPlayerFromCharacter. From there you can refer to the exp object inside your statsfolder and add however amount of exp you want to give. Hope this helps!
The script that checks this must be inside your weapon.
Here is an example:
local Tool = script.Parent -- assuming its a script inside a sword
local debounce = false
Tool.Handle.Touched:Connect(function(hit)
local character = Tool.Parent
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false and not hit:IsDescendantOf(character) then
debounce = true
hit.Parent.Humanoid:TakeDamage(20)
if hit.Parent.Humanoid.Health <= 0 then
-- give exp
end
task.wait(0.9)
debounce = false
end
end
end)
If in case its a gun its nothing more than making bullet.Touched
game:GetService("Players").PlayerAdded:Connect(function(player)
if player then
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local statsfolder = Instance.new("Folder")
statsfolder.Name = "stats"
statsfolder.Parent = player
local levelval = Instance.new("IntValue")
levelval.Parent = leaderstats
levelval.Name = "Level"
local exp = Instance.new("IntValue")
exp.Parent = statsfolder
exp.Name = "EXP"
local requiredexp = Instance.new("IntValue")
requiredexp.Parent = statsfolder
requiredexp.Name = "RequiredEXP"
requiredexp.Value = 100
exp.Changed:Connect(function()
if exp.Value >= requiredexp.Value then
levelval.Value = levelval.Value + 1
exp.Value = 0
requiredexp.Value = requiredexp.Value * 2
end
end)
-- Assume the enemy's Humanoid dies here (you'll need to adapt this part)
enemyHumanoid.Died:Connect(function()
local killerPlayer = game.Players:GetPlayerFromCharacter(enemyHumanoid.Parent)
if killerPlayer then
-- Adjust the amount of EXP to grant per enemy kill
local expToGrant = 50
exp.Value = exp.Value + expToGrant
end
end)
end
end)