Hi everyone, I’m having struggles with something. I’m trying to show the players on server but its not budging, it gets the players level when you first load in but it wont update when you level up, i did try the IntValue.Changed, still not budging.
local repstorage = game.ReplicatedStorage.BillboardGui.StatShower
game.Players.PlayerAdded:Connect(function(player)
local levels = player:WaitForChild("leaderstats").Levels
repstorage.Text = "Level: "..levels.Value
end)
end)
This script makes it where you spawn with a gui on your head
local repstorage = game.ReplicatedStorage.BillboardGui
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local cloneUI = repstorage:Clone()
cloneUI.Parent = character.Head
end)
end)
So where you see the level counter on the bottem left corner, thats local, im trying to make the billboard gui serverside, so everyone can see your level, ive been trying to solve this issue for a couple of days now.
Alright i did as you said, i only used this script you gave nothing else, it cloned the gui and stuff, it shows the level you spawned with, but when i level up it doesnt change, it stays at the same level you started with
Yes, the problem is exactly what @RandomPlayerOne1 mentioned. Although, I would personally go a different route with the solution to that as to save performance (even if only a sliver)
local repstorage = game.ReplicatedStorage.BillboardGui
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local cloneUI = repstorage:Clone()
cloneUI.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
cloneUI.Parent = character.Head
end)
player:WaitForChild("leadersats"):WaitForChild("Levels"):GetPropertyChangedSignal("Value"):Connect(function()
if player.Character and player.Character:FindFirstChild("BillboardGui") then
player.Character.BillboardGui.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
end
end)
end)
Quickly made a datastore with “Swings”, “XP”, “Levels”
I tested and it worked, please let me know if it works for you.
This is the only script you need.
If this doesn’t work make sure you’re changing your level in the server, not the client.
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Test")
local function levelsGui(player, levels)
task.wait(0.1)
local character = player.Character
local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
CloneUI.Parent = character:FindFirstChild("Head")
CloneUI.TextLabel.Text = levels.Value -- whatever the textLabel is inside of "CloneUI"
levels.Changed:Connect(function()
local newVal = "Level: "..levels.Value
CloneUI.TextLabel.Text = "Level: "..newVal -- whatever the textLabel is inside of "CloneUI"
end)
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local swings = Instance.new("NumberValue", leaderstats)
swings.Name = "Swings"
swings.Value = 0
local experience = Instance.new("NumberValue", leaderstats)
experience.Name = "XP"
experience.Value = 0
local levels = Instance.new("NumberValue", leaderstats)
levels.Name = "Levels"
levels.Value = 0
local dataSwings
local dataXP
local dataLevels
local success, failure = pcall(function()
local key1 = player.UserId.."Swings"
local key2 = player.UserId.."XP"
local key3 = player.UserId.."Levels"
dataSwings = dataStore:GetAsync(key1)
dataXP = dataStore:GetAsync(key2)
dataLevels = dataStore:GetAsync(key3)
end)
if success then
if dataSwings and dataXP and dataLevels ~= nil then
swings.Value = dataSwings
experience.Value = dataXP
levels.Value = dataLevels
print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
player.CharacterAdded:Connect(function()
levelsGui(player, levels)
end)
else
print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
player.CharacterAdded:Connect(function()
levelsGui(player, levels)
end)
end
else
print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
warn(failure)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, failure = pcall(function()
local key1 = player.UserId.."Swings"
local key2 = player.UserId.."XP"
local key3 = player.UserId.."Levels"
dataStore:SetAsync(key1, player.leaderstats.Swings.Value)
dataStore:SetAsync(key2, player.leaderstats.XP.Value)
dataStore:SetAsync(key3, player.leaderstats.Levels.Value)
end)
if success then
print("Data saved successfully: ["..player.Name.."; "..player.UserId.."]")
else
print("Data not saved: ["..player.Name.."; "..player.UserId.."]")
warn(failure)
end
end)
So the data save works, so does the leaderstats, but the billboard gui doesnt seem to be showing, I even fixed the text lable path, i even tested it on a clear baseplate, i even put it in the server. But if theres anything im doing wrong just tell me
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Test")
local function levelsGui(player, levels)
task.wait(0.1)
local character = player.Character
local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
CloneUI.Parent = character:FindFirstChild("Head")
CloneUI.StatShower.Text = levels.Value -- whatever the textLabel is inside of "CloneUI"
levels.Changed:Connect(function()
local newVal = "Level: "..levels.Value
CloneUI.StatShower.Text = "Level: "..newVal -- whatever the textLabel is inside of "CloneUI"
end)
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local swings = Instance.new("NumberValue", leaderstats)
swings.Name = "Swings"
swings.Value = 0
local experience = Instance.new("NumberValue", leaderstats)
experience.Name = "XP"
experience.Value = 0
local levels = Instance.new("NumberValue", leaderstats)
levels.Name = "Levels"
levels.Value = 0
local dataSwings
local dataXP
local dataLevels
local success, failure = pcall(function()
local key1 = player.UserId.."Swings"
local key2 = player.UserId.."XP"
local key3 = player.UserId.."Levels"
dataSwings = dataStore:GetAsync(key1)
dataXP = dataStore:GetAsync(key2)
dataLevels = dataStore:GetAsync(key3)
end)
if success then
if dataSwings and dataXP and dataLevels ~= nil then
swings.Value = dataSwings
experience.Value = dataXP
levels.Value = dataLevels
print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
player.CharacterAdded:Connect(function()
levelsGui(player, levels)
end)
else
print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
player.CharacterAdded:Connect(function()
levelsGui(player, levels)
end)
end
else
print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
warn(failure)
end
Alright, I fixed the script I have made, here it is.
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Test")
local function levelsGui(player, levels)
player.CharacterAdded:Connect(function(character)
local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
CloneUI.Parent = character:FindFirstChild("Head")
CloneUI.TextLabel.Text = "Level: "..levels.Value -- whatever the textLabel is inside of "CloneUI"
levels.Changed:Connect(function()
local newVal = "Level: "..levels.Value
CloneUI.TextLabel.Text = newVal -- whatever the textLabel is inside of "CloneUI"
end)
end)
if player.Character then
local character = player.Character
local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
CloneUI.Parent = character:FindFirstChild("Head")
CloneUI.TextLabel.Text = "Level: "..levels.Value -- whatever the textLabel is inside of "CloneUI"
levels.Changed:Connect(function()
local newVal = "Level: "..levels.Value
CloneUI.TextLabel.Text = newVal -- whatever the textLabel is inside of "CloneUI"
end)
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local swings = Instance.new("NumberValue", leaderstats)
swings.Name = "Swings"
swings.Value = 0
local experience = Instance.new("NumberValue", leaderstats)
experience.Name = "XP"
experience.Value = 0
local levels = Instance.new("NumberValue", leaderstats)
levels.Name = "Levels"
levels.Value = 0
local dataSwings
local dataXP
local dataLevels
local success, failure = pcall(function()
local key1 = player.UserId.."Swings"
local key2 = player.UserId.."XP"
local key3 = player.UserId.."Levels"
dataSwings = dataStore:GetAsync(key1)
dataXP = dataStore:GetAsync(key2)
dataLevels = dataStore:GetAsync(key3)
end)
if success then
if dataSwings and dataXP and dataLevels ~= nil then
swings.Value = dataSwings
experience.Value = dataXP
levels.Value = dataLevels
print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
print("1")
levelsGui(player, levels)
else
print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
levelsGui(player, levels)
end
else
print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
warn(failure)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, failure = pcall(function()
local key1 = player.UserId.."Swings"
local key2 = player.UserId.."XP"
local key3 = player.UserId.."Levels"
dataStore:SetAsync(key1, player.leaderstats.Swings.Value)
dataStore:SetAsync(key2, player.leaderstats.XP.Value)
dataStore:SetAsync(key3, player.leaderstats.Levels.Value)
end)
if success then
print("Data saved successfully: ["..player.Name.."; "..player.UserId.."]")
else
print("Data not saved: ["..player.Name.."; "..player.UserId.."]")
warn(failure)
end
end)
You need the game published for the DataStoreService, with “Allow HTTP Requests” and “Enable Studio Access to API Services” enabled. You can find these two options in the game settings.