I have a game where players jump to gain JumpPower and XP, which is activated by ‘MouseButton1Down’. Each time the player jumps, points are added (JumpPower and XP).
XP is visually shown in the UI as a level bar that increases as the player gains XP until the next level is reached.
On PC everything works, but on mobile and console, the level bar does not fill up (I do not have a console to test it, but got bug reports from players).
What am I doing wrong? I do not seem to find the problem (there is no error message).
I am not sure how to go about fixing this. Any input or pointers would be much appreciated
This is my code:
–******–
–// in StarterPlayer.StarterPlayerScripts
local plr = game.Players.LocalPlayer
local Remote = workspace.Events.AddPoints
local Debounce = true
local Char = plr.Character or plr.CharacterAdded:Wait()
local Key = 'MouseButton1Down'
local mouse = plr:GetMouse()
mouse.KeyDown:Connect(function(key)
if key:byte() == 32 then
if Debounce and Char and Char.Humanoid.Jump == false then
Debounce = false
Remote:FireServer()
end
end
wait(2)
Debounce = true
end)
–******–
–// event placed in a script in workspace
script.AddPoints.OnServerEvent:Connect(function(plr)
if plr.PlayerStats.Rebirths.Value > 1 then
if plr.PlayerStats.Level.Value > 1 then
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2 *(plr.PlayerStats.Rebirths.Value+plr.PlayerStats.Level.Value))
else
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2 *(plr.PlayerStats.Rebirths.Value))
end
else
if plr.PlayerStats.Level.Value > 1 then
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2+plr.PlayerStats.Level.Value)
else
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2)
end
end
if plr.PlayerStats.DoubleJump.Value == true then
if plr.PlayerStats.Rebirths.Value > 1 then
if plr.PlayerStats.Level.Value > 1 then
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2 *plr.PlayerStats.Rebirths.Value)+plr.PlayerStats.Level.Value
else
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2 *(plr.PlayerStats.Rebirths.Value))
end
else
if plr.PlayerStats.Level.Value > 1 then
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2+plr.PlayerStats.Level.Value)
else
plr.PlayerStats.JumpPower.Value = plr.PlayerStats.JumpPower.Value + (.2)
end
end
end
plr.PlayerStats.XP.Value = plr.PlayerStats.XP.Value +1
end)
–******–
–// in StarterGUI, local script
local function levelBarDisplay ()
--//Display Levelbar progress
--// script credit for level bar: @Elttob
local xp = XP.Value
local level = Level.Value
local Base = interface.Toggles.Trackers.Level.Base -- change this to refer to your Base ImageLabel
local oneOverProgress
local total
if level == 0 then total = 50 else total = level*50 end
local progress = xp/total
if progress == 0 then
oneOverProgress = 0
else
oneOverProgress = 1/progress
end
--// Loadingbar-fill
Base.Clipping.Size = UDim2.new(progress, 0, 1, 0)
Base.Clipping.Top.Size = UDim2.new(oneOverProgress, 0, 1, 0)
wait()
end
levelBarDisplay()
-- XP increase displays change in tracker bar
plr.PlayerStats.XP.Changed:Connect(function()
levelBarDisplay()
end)