I created a simple GUI that i want to script so whenever a player levels up or have a currency change, a notification will appear. Right now i’m focused on the Level Up notification but i dont know how to do it since i’m a beginner at scripting. Does it has to be included in the level system script or the local script can be in the notification UI?
Here is some information about it
The script i wanted to put the UI notification tween and function in
local DataStoreService = game:GetService("DataStoreService")
local Ds = DataStoreService:GetDataStore("Ds")
game.Players.PlayerAdded:Connect(function(player)
local Prefix = player.UserId
local level = Instance.new("IntValue", player)
level.Name = "Level"
level.Value = 1
local exp = Instance.new("IntValue", level)
exp.Name = "Current"
exp.Value = 0
local maxExp = Instance.new("IntValue", level)
maxExp.Name = "Max"
maxExp.Value = 100
local data
local success,errormessage = pcall(function()
data = Ds:GetAsync(Prefix)
end)
if success then
level.Value = data.level
exp.Value = data.current
maxExp.Value = data.maxExp
end
exp.Changed:Connect(function(val)
if exp.Value >= maxExp.Value then
-- Do stuff.
level.Value = level.Value + 1
exp.Value = 0
maxExp.Value = maxExp.Value * 1.25
end
end)
while true do
exp.Value = exp.Value + 5
wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Prefix = player.UserId
local data = {
level = player.Level.Value;
current = player.Level.Current.Value;
maxExp = player.Level.Max.Value}
local success,errormessage = pcall(function()
Ds:SetAsync(Prefix, data)
end)
if success then
print("Data Succesfully saved!")
else
print("Error saving data!")
warn(errormessage)
end
end)
The placement of the notification UI [highlighted]
I tried to use the Changed event but failed many times so this is why im asking for help here.
Thank you
You really don’t want your server scripts to mess with anything on the client, including their playerGUIs. With this in mind I can see you have a changed event, which is fine in the context of exp.
But there is quite the issue, you see, you haven’t parented any of those values into the serverstorage. The changed event cannot fire for a value that doesn’t exist in the workspace yet. You merely need to create a folder with the players name, and put the three values in there.
Never mind your using the inefficient method to parent. Please don’t use that method, and please do this instead as you dont want these values put into your local player.
You don’t need to place these values in serverstorage if you want them to be read by the client. But to keep it simple just put them in serverstorage.
As for the notification, remote events will help you there. Just have the local script connect to a remote events call, and do what you want (firing the remote event when they level up in the changed function).
That would be the Value of the Level, for example 1. You’ll just want the LocalPlayer.Level.
Keep in mind that’s where function parameters are defined, you’ll want to put your code after the function parenthesis. Additionally, don’t forget end the close the function’s scope.
As I said, it’s the Value of the NumberValue/IntValue so for example you’d be defining lvlchange as 1.
Defining it as just game:GetService("Players").LocalPlayer.Level would be the NumberValue/IntValue which of course has the Changed event.
For the past 2 days i’ve been trying to fix this by myself but i cannot find the problem. The script you gave me works as intended, the level number is changing to the actual Level.Value but now the EXP bar wont move and the Level IntValue cannot be found in the player’s inventory.
What i meant by that: The “Level” IntValue should be above Stamina . The yellow/green bar is the EXP bar and should fill as the player gains EXP.
I did not changed many things at the scripts , instead, i tried to make it over and over again by watching YouTube tutorials or ready the Dev Hub.
local DataStoreService = game:GetService("DataStoreService")
local Ds = DataStoreService:GetDataStore("Ds")
local notification = game.ReplicatedStorage.Notification
game.Players.PlayerAdded:Connect(function(player)
local Prefix = player.UserId
local folder = Instance.new("Folder")
folder.Name = player.Name
folder.Parent = game.ServerStorage
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
level.Parent = folder
local exp = Instance.new("IntValue")
exp.Name = "Current"
exp.Value = 0
exp.Parent = folder
local maxExp = Instance.new("IntValue")
maxExp.Name = "Max"
maxExp.Value = 100
maxExp.Parent = folder
local data
local success,errormessage = pcall(function()
data = Ds:GetAsync(Prefix)
end)
if success then
level.Value = data.level
exp.Value = data.current
maxExp.Value = data.maxExp
end
exp.Changed:Connect(function(val)
if exp.Value >= maxExp.Value then
-- Do stuff.
level.Value = level.Value + 1
exp.Value = 0
maxExp.Value = maxExp.Value * 1.25
notification:FireClient(player,"LEVEL",level.Value)
end
end)
while true do
exp.Value = exp.Value + 5
wait(.1)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Prefix = player.UserId
local folder = game.ServerStorage
local data = {
level = folder.Level.Value;
current = folder.Current.Value;
maxExp = folder.Max.Value}
local success,errormessage = pcall(function()
Ds:SetAsync(Prefix, data)
end)
if success then
print("Data Succesfully saved!")
else
print("Error saving data!")
warn(errormessage)
end
end)
and the script inside the lvl number text
local p = script.Parent
game.ReplicatedStorage.Notification.OnClientEvent:Connect(function(type,value)
if type == "LEVEL" then
p.Text = value
end
end)
As i said , the Event works but now the level bar is not moving and the Level IntValue does not exist.
Thank you for helping me