Continuous experience GUI Effect

I’m currently developing a game that gives players 1 experience points every 0.5 seconds, as long as they are online in the game. I’m trying to make it so that every time this action is triggered (experience.Value = experience.Value + 1), it as well spawns an XP icon by the level bar and flows upward then fades away (similar to simulator games). I’m fairly new to using the tween service and don’t exactly know where to begin programming something like this.

I’ve looked around at other examples and I believe I have to use a LocalScript? Or is it possible to where I can just embed it into a regular script?

Here’s the code block that is embedded in a script located in the ServerScriptService:

	while wait() do
		
		local levelBar = player.PlayerGui:WaitForChild("LevelBar")	
		
		if level.Value < 1 then 
			
			expToLevelUp = 100 
			
		else
			
			expToLevelUp = math.floor(level.Value) + 100 + math.floor(level.Value ^ 2)
		end
		
		
		if experience.Value >= expToLevelUp then
			
			level.Value = level.Value + 1	
		end
		
		expForPreviousLevel = math.floor(level.Value - 1) + 100 + math.floor((level.Value - 1) ^ 2)
		
		
		local expDifference = expToLevelUp - expForPreviousLevel

		local expDifference2 = experience.Value - expForPreviousLevel
			
		
		levelBar.Bar:TweenSize(UDim2.new(levelBar.BarBackground.Size.X.Scale * (expDifference2 / expDifference), 0, levelBar.BarBackground.Size.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.001)
		
		levelBar.Experience.Text = expDifference2 .. "/" .. expDifference
		
		levelBar.Level.Text = "Level: " .. level.Value
		
		wait(0.5)
		experience.Value = experience.Value + 1
	end			
end)
```

It can be part of a server side script, but you will need to reference each player GUI from there which would then have to replicate to client side.

tbh it’s easier to make this a LocalScript and use an event listener to run a function when the value changes.

I use the following which is fired when the user performs a task which displays a Frame rising up for 1 second. Change to suit your circumstances

local player = game.Players.LocalPlayer
local cashFrame = player.PlayerGui.ScreenGui.CashMarker
local cashSound = player.PlayerGui.ScreenGui.CashSound

local function cashGUI()
		local giveCash = "+ $100"
		cashSound:Play()
		cashFrame.Visible = true
		cashFrame.Position = cashFrameStartPos
		local willPlay = cashFrame:TweenPosition(
			UDim2.new(0.5, 0, 0.3, 0),	-- Final position the tween should reach
			Enum.EasingDirection.In,	-- Direction of the easing
			Enum.EasingStyle.Sine,		-- Kind of easing to apply
			1,							-- Duration of the tween in seconds
			false						-- Whether in-progress tweens are interrupted
		)
		wait(1)
		cashFrame.Visible = false
end
1 Like

Thanks for the reply! I am currently trying to use your script and changed it to what I believed to be functional, but apparently not. The output returns no errors at all, but nothing is happening. I made it a LocalScript which may be part of the problem, but I believe you are not able to find LocalPlayer simply using a regular script. Here’s what I did:

local player = game.Players.LocalPlayer
local expFrame = player.PlayerGui:WaitForChild("expIcon").expIcon

local function expEffects()
	expFrame.Visible = true
	expFrame.Position = UDim2.new(0.014, 0,0.888, 0)
	local willPlay = expFrame:TweenPosition(
		UDim2.new(0.011, 0, 0.775, 0),	
		Enum.EasingDirection.In,	
		Enum.EasingStyle.Sine,		
		1,							
		false						
	)
	wait(1)
	expFrame.Visible = false
end

Any help at all is greatly appreciated! Thanks!

I can’t see any :Play() that’s why it’s not playing at all.

1 Like

This

local expFrame = player.PlayerGui:WaitForChild("expIcon").expIcon

Can you show me a screenshot of where that frame is in your StarterGui.
Mine looks like this:
image
So when I reference it under the Player, it becomes:
local cashFrame = player.PlayerGui.ScreenGui.CashMarker