So I have a fully functional Level/XP system, I tested it out by putting a brick down and putting a script into the brick that says:
local debounce = false
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
player.LevelSystem.Exp.Value += 10
wait(1)
debounce = false
end
end
end)
When I touch the brick, it works fine and I get the xp, and once I reach the xp goal to level up, It levels me up and resets the xp, It works fine. BUT, When I tried to give myself xp from killing players, the xp goes up just fine, but once it reaches the xp goal to level up, It doesn’t level up and keeps adding on to the previous xp, there are no errors in the output so I’m confused, here’s the local script for gaining kill xp.
-- // Services
-- External services
local tweenService = game:GetService("TweenService")
-- Default services
local replicatedStorage = game:GetService("ReplicatedStorage")
local playersService = game:GetService("Players")
-- // Variables
-- Comms variables
local killEvent = replicatedStorage:WaitForChild("KillNotification")
-- Player variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- UI variables
local killGUI = script.Parent
local brightness = killGUI:WaitForChild("Brightness")
local notification = killGUI:WaitForChild("Notification")
local Cash = killGUI:WaitForChild("Cash")
local killSound = script:WaitForChild("KillSound")
-- // Functions
local function tweenTransparency(guiObject, duration, transparency, Override)
spawn(function()
local tween = nil
if guiObject:IsA("TextLabel") then
local tween = tweenService:Create(guiObject, TweenInfo.new(duration), {TextTransparency = transparency}, {Override = Override})
tween:Play()
spawn(function()
tween.Completed:Wait()
tween:Destroy()
end)
elseif guiObject:IsA("ImageLabel") then
local tween = tweenService:Create(guiObject, TweenInfo.new(duration), {ImageTransparency = transparency}, {Override = Override})
tween:Play()
spawn(function()
tween.Completed:Wait()
tween:Destroy()
end)
end
if tween ~= nil then
return tween
end
end)
end
local activeTextLabel = script.Value
local function notify(victim)
player.LevelSystem.Exp.Value += 10
if activeTextLabel == true then
repeat
wait(.05)
until not activeTextLabel == true
end
activeTextLabel = true
notification.TextTransparency = 1
Cash.TextTransparency = 1
notification.Text = "<font color='#ff3a3a'>Eliminated: </font>" .. victim.Name
killSound:Play()
tweenTransparency(notification, 0.5, 0, true)
tweenTransparency(Cash, 0.5, 0, true)
notification:TweenSize(UDim2.new(0.302, 0, 0.052, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
Cash:TweenSize(UDim2.new(0.302, 0, 0.071, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
wait(0.1)
notification:TweenSize(UDim2.new(0.216, 0, 0.037, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
Cash:TweenSize(UDim2.new(0.216, 0, 0.051, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
wait(1.5)
tweenTransparency(Cash, 0.3, 1, true)
tweenTransparency(notification, 0.3, 1, true)
activeTextLabel = false
end
-- // Connections
killEvent.OnClientEvent:Connect(notify)
The XP is given on line 65 where it says
player.LevelSystem.Exp.Value += 10
Here is the script inside of ServerScriptService that causes the player to level up and reset their xp once their XP reaches the level up goal.
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "LevelSystem"
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", leaderstats)
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 * 10
end
end)
end)
How can I solve this issue?