Changing ways to get XP in a leveling script? (Urgent Advice Needed)

For my One-Piece game I have recently made a leveling system with the help of a tutorial. My aim now is to change ways to get XP. As of now the only way to get XP is by touching a scripted block. But I want to be able to gain XP by killing NPC’s and players. How do I do this? I will be leaving the script I used to make the leveling system below so any people willing to help can make edits and hopefully help me find a solution:

(FOR THOSE WHO WONDER WHY I SOUND LIKE I DONT KNOW WHAT IM TALKING ABOUT I DO NOT USUALLY DO SCRIPTING)

(SOME SCRIPT IS IN THE REPLY SECTION)

For the leaderboard:

	
	
	
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Level = Instance.new("NumberValue", leaderstats)
	Level.Name = "Level"
	Level.Value = 1
	
	local Exp = Instance.new("NumberValue", leaderstats)
	Exp.Name = "Exp"
	Exp.Value = 0
	
	local RequiredExp = Instance.new("NumberValue", Player)
	RequiredExp.Name = "RequiredExp"
	RequiredExp.Value = Level.Value * 100
	
	
	
	Exp.Changed:Connect(function(Changed)
		if Exp.Value >= RequiredExp.Value then
			Exp.Value = 0
			
			Level.Value += 1
			RequiredExp.Value = Level.Value * 100
		end
	end)
end) ```

For the GUI:


local Exp = Player.leaderstats.Exp
local RequiredExp = Player.RequiredExp

Exp.Changed:Connect(function(Changed)
	if Changed then
		script.Parent.ExpBar:TweenSize(UDim2.new(Exp.Value/RequiredExp.Value, 0, 1, 0))
	end
end)

while wait() do
	script.Parent.ExpLabel.Text = Exp.Value.."/"..RequiredExp.Value
end

-------------------THE OTHER SCRIPT------------------------------------------

local Player = game.Players.LocalPlayer

while wait() do
	script.Parent.Text = "Level :"..Player.leaderstats.Level.Value
end```

Just change the value of the Exp value. It shouldn’t be hard at all.

player.leaderstats.Exp.Value += 100

He should change Exp value on the server, where he probably calculates all the attack mechanics.
You shouldn’t use RemoteEvents when you can just use Tool.Activated (where he is damaging/killing enemies) for this situation.

I don’t think you know how FilteringEnabled works.

If you change a value visible to all players on the server, all clients will also see the change.
If you change a value from the client though, only they themselves will see it.

Oh hang on- yeah your right. I’ve got myself confused : /

Is there a specific time where you could discuss how to do this via private chat? Completely fine if your not willing. But I think you may have cracked it.

I’m sorry but I don’t think there is much to talk about. All you have to do is increase the value and that’s it. If you have problems doing so you can tell me but it’s pretty clear on what to do.

So by simply changing the value, I can make it so you gain XP from killing players and NPCS?
Sounds too good to be true.
Also, I don’t want this to be per kill, I want it to be per hit

Uhh this is just Roblox scripting. You can detect when the player hits something, and then just add the value.

Something tells me he doesnt understand…

1 Like

something also tells me this may be a freemodel

because he uses free models?

Or he followed a tutorial not knowing what the code really means…

I completely misunderstood the situation,I have figured it out and no I don’t use free models and closely examined the script to see if I could learn something myself. The reason for the misunderstanding was because I didn’t know what he was referring to when he said “Change Values” However it’s all sorted now. 30% of my game done.

No, it’s not a free model, it’s a script that was made by someone else but I wrote it out and did everything else. I usually do commissions on separate accounts and stuff like that, so I scripting isn’t usually a thing I’d do. I’m not an al rounds dev.