Level system Problem

Hello I made a level system for my game and I want to make it so that when I kill someone I get 50 exp
I just need to add this code somewhere

Player.Data.Exp.Value  +=50

ale nie wiem gdzie to dodać
dodam też że robiłem level system z tutorialem

could someone help me to lighten up the situation ?

Should I add this to the weapons script or what?

thanks in advance for your reply

You should add it to your weapons script.

In which place?

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Player
local Character
local Humanoid
--local TEAM
local VisualizeBullet = script.Parent:WaitForChild("VisualizeBullet")
local Module = require(Tool:WaitForChild("Setting"))
local ChangeAmmoAndClip = script:WaitForChild("ChangeAmmoAndClip")
local InflictTarget = script:WaitForChild("InflictTarget")
local Grip2
local Handle2

if Module.DualEnabled then
	Handle2 = Tool:WaitForChild("Handle2",1)
	if Handle2 == nil and Module.DualEnabled then error("\"Dual\" setting is enabled but \"Handle2\" is missing!") end
end

local AmmoValue = script:FindFirstChild("Ammo") or Instance.new("NumberValue",script)
AmmoValue.Name = "Ammo"
AmmoValue.Value = Module.AmmoPerClip
local ClipsValue = script:FindFirstChild("Clips") or Instance.new("NumberValue",script)
ClipsValue.Name = "Clips"
ClipsValue.Value = Module.LimitedClipEnabled and Module.Clips or 0

if Module.IdleAnimationID ~= nil or Module.DualEnabled then
	local IdleAnim = Instance.new("Animation",Tool)
	IdleAnim.Name = "IdleAnim"
	IdleAnim.AnimationId = "rbxassetid://"..(Module.DualEnabled and 53610688 or Module.IdleAnimationID)
end
if Module.FireAnimationID ~= nil then
	local FireAnim = Instance.new("Animation",Tool)
	FireAnim.Name = "FireAnim"
	FireAnim.AnimationId = "rbxassetid://"..Module.FireAnimationID
end
if Module.ReloadAnimationID ~= nil then
	local ReloadAnim = Instance.new("Animation",Tool)
	ReloadAnim.Name = "ReloadAnim"
	ReloadAnim.AnimationId = "rbxassetid://"..Module.ReloadAnimationID
end
if Module.ShotgunClipinAnimationID ~= nil then
	local ShotgunClipinAnim = Instance.new("Animation",Tool)
	ShotgunClipinAnim.Name = "ShotgunClipinAnim"
	ShotgunClipinAnim.AnimationId = "rbxassetid://"..Module.ShotgunClipinAnimationID
end

ChangeAmmoAndClip.OnServerEvent:connect(function(Player,Ammo,Clips)
	AmmoValue.Value = Ammo
	ClipsValue.Value = Clips
end)
InflictTarget.OnServerEvent:connect(function(Player,TargetHumanoid,TargetTorso,Damage,Direction,Knockback,Lifesteal,FlamingBullet)
	local targetPlayer = game:GetService("Players"):GetPlayerFromCharacter(TargetHumanoid.Parent)
	if targetPlayer and targetPlayer.Team == Player.Team then return end -- They were on the same team, abort
	if Player and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso then
		while TargetHumanoid:FindFirstChild("creator") do
			TargetHumanoid.creator:Destroy()
		end
		local creator = Instance.new("ObjectValue",TargetHumanoid)
		creator.Name = "creator"
		creator.Value = Player
		game.Debris:AddItem(creator,5)
		TargetHumanoid:TakeDamage(Damage)
		if Knockback > 0 then
			TargetTorso.Velocity = Direction * Knockback
		end
		if Lifesteal > 0 and Humanoid and Humanoid.Health ~= 0 then
			Humanoid.Health = Humanoid.Health + (Damage*Lifesteal)
		end
		if FlamingBullet then
			local Debuff = TargetHumanoid.Parent:FindFirstChild("IgniteScript") or script.IgniteScript:Clone()
			Debuff.creator.Value = Player
			Debuff.Disabled = false
			Debuff.Parent = TargetHumanoid.Parent
		end
	end
end)

Tool.Equipped:connect(function()
	Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
	Character = Tool.Parent
	Humanoid = Character:FindFirstChild("Humanoid")
	--TEAM = Character:FindFirstChild("TEAM")
	if Module.DualEnabled and Workspace.FilteringEnabled then
		Handle2.CanCollide = false
		local LeftArm = Tool.Parent:FindFirstChild("Left Arm")
		local RightArm = Tool.Parent:FindFirstChild("Right Arm")
		if RightArm then
			local Grip = RightArm:WaitForChild("RightGrip",0.01)
			if Grip then
				Grip2 = Grip:Clone()
				Grip2.Name = "LeftGrip"
				Grip2.Part0 = LeftArm
				Grip2.Part1 = Handle2
				--Grip2.C1 = Grip2.C1:inverse()
				Grip2.Parent = LeftArm
			end
		end
	end
end)

Tool.Unequipped:connect(function()
	if Module.DualEnabled and Workspace.FilteringEnabled then
		Handle2.CanCollide = true
		if Grip2 then Grip2:Destroy() end
	end
end)

this is my problem i don`t know where?
Can you help me?
it is gun script serw

When you damage someone using your weapon, add a value inside their character (removing any old ones incase someone else hit them) so that when that character dies. They check the value of the killer and give them exp.

The correct way is before the damage is done, check if player’s health - damage is equal to 0 or smaller. If it is, then it’s a confirmed kill.

1 Like

what to finally do?
And can you write
a bit simpler for me because I just started with lua
and gun is`n mine

bad idea. there could be more weapons that dont have it

the best idea is to do what everybody else does even roblox

when doing damage add an object value called “creator” case sensitive, set the parent to the one who got killed’s humanoid and set the value to the killer’s player object

for example:
player1 damaged player2
create creator object value
set parent to player2’s character humanoid
set value to player1 (the player object)

make sure to delete it a tenth of a second later (0.1) using debris
Debris:AddItem(value, 0.1)

now in a completely different script have a connection for players added, then connect to their character added, then connect to their humanoid died, then check if they have a creator value (use the first one found, it will be the more recent person who did damage, FindFirstChild) then you get the value of that to get the killer and give the killer 50 exp

Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char:WaitForChild("Humanoid").Died:Connect(function()
            if char.Humanoid:FindFirstChild('creator')
                local creator = char.Humanoid.creator
                if creator.Value then
                    creator.Value.Data.Exp.Value += 50
                end
            end
        end)
    end)
end)
local tool = script.Parent
local me = game.Players:GetPlayerFromCharacter(tool.Parent)

local function Activiting(hit)

local Human = hit.Parent:FindFirstChild("Humanoid")

if Human then
Human.Died:Connect(function()
local Data = me:FindFirstChild("Data")
local Exp = Data:WaitForChild("Exp")
if Exp then
Exp.Value += 50
end
end)
end

end

tool.Activated:Connect(Activiting)

am I right doing this?

1 Like

This is correct, if you want to add assists though then you will have to use my option though.

In which place add this script in gun script serwer ? if yes i which
line of code I tried to understand it but it didn’t work

Thank you in advance

Overall there was a problem with the system solved
it was simply done wrong
Player.Data.Exp.Value +=50
powinno być inaczej

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.