Would I put this script in StarterPlayerScripts or somewhere else?

Hello!

I am working on a basic levelling up system, and I need help with where to put the script below. Currently, I have it in StarterPlayerScripts but I’m unsure if it needs to be somewhere else.

local player = game.Players.LocalPlayer
local repStorage = game.ReplicatedStorage
local event = repStorage.RemoteEvents.LevelUp

-- Stats

local LevelStats = player.LevelStats
local Level = LevelStats.Level
local XP = LevelStats.XP

-- Str Values

local neededXP = 500 * Level.Value

-- Update function

local function update()
	if XP.Value >= neededXP then
		event:FireServer()
	else
		Level.Value = Level.Value
		XP.Value = XP.Value 
	end
end

XP.Changed:Connect(function()
	update()
end)

The purpose of the script is to check the Player’s XP value and see if they have enough to then progress to the next Level, but it’s automatic so once they reach the required amount, they automatically level up.

Just need to know if this will work in StarterPlayerScripts, or if I need to change it to somewhere else and to a different type of script because it’s a LocalScript right now.

This is not something I would do on the client in the first place. Why go through the trouble of detecting the change in XP on the client only to then send a request back to the server?

Personally, I would check if the player’s current XP exceeds the requiredXP on the server, at the same spot that you increase the XP. This would clean up your code by making the local script you sent redundant and it also gets rid of an unnecessary RemoteEvent.

I hope this helps :slight_smile:

1 Like