Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

When a player dies, they have the highest players level?

To keep it simple, this script I made shows the characters level above their head. And yes I know I've set it to update every time the player dies because thats how I want it to work. But the thing is, say a player is level 3 and another 2 players are level 1. When those two players die they both show level 3 above their heads. It's pretty much taking the highest players level and showing it above everyone.

Is there any simple way around this?

Thanks in advance for help!

function CharacterRemoving(newPlayer)
	wait(1)
	while true do
	wait(0.1)
		if xp.Value >= 100 then
			levels.Value = levels.Value + 1
			xp.Value = 0
		end
		gui=Instance.new("BillboardGui")
		gui.Parent=newPlayer.Character.Head
		gui.Adornee=newPlayer.Character.Head
		gui.Size=UDim2.new(3,0,2,0)
		gui.StudsOffset=Vector3.new(0,2,0)
		text=Instance.new("TextLabel")
		text.Text = "Level " .. levels.Value
		text.Size=UDim2.new(1.25,0,0.5,0)
		text.Position=UDim2.new(-0.125,0,-0.25,0)
		text.BackgroundTransparency = 1
		text.Parent=gui
		text.FontSize = ("Size36")
		text.Font = ("ArialBold")
		text.TextColor3 = Color3.new(255, 255, 0)
		text.TextStrokeColor3 = Color3.new(0, 0, 0)
		text.TextStrokeTransparency = 0
		w = game.Lighting.WepsGroup:GetChildren() 
		for i = 1,#w do
			w[i]:Clone().Parent = newPlayer.Backpack
		end
	end
	end

function onPlayerEntered(newPlayer) 
newPlayer.Changed:connect(function (property) 
if (property == "Character") then 
CharacterRemoving(newPlayer)

2 comments

0

Replied. I would reply faster, but for some reason, I'm not getting a notification from this question, when you comment.

0

Thats alright, but yeah i've tried removing the while loop I really can't figure out the cause. I would post the whole script so people could look further into it but its 124 lines long and would probably be classed as spam.

1 answer

Assuming this isn't your whole script, the problem is your xp and levels variable. You never had them reset each time a character dies. So, at the beginning of the function, line 2, set both of those values correctly, by accessing wherever it is. For example, if their xp values were leaderstats, have it access the Player's leaderstats, and proceed with your code.

4 comments

0

Thanks I understand where you're coming from and it actually makes a lot of sense. But any idea how I would make it access each players leaderstats induvdually? Because the script has no way of working out what player its loading the levels value for when they reset?

0

Actually, your script does have a way of working it out. The parameter ,newPlayer, is the Player! From there, you can do newPlayer.leaderstats.Level, and so on! Call it within the function!

0

Hmmm I've tried this with 3 or 4 people on my game and written the levels variable like this text.Text = "Level " .. newPlayer.leaderstats.Levels.Value But if I die the same time as another player it will give us both the same level from either one of us for the rest of our time in-game.

0

@Cuvette Hm, maybe Try remove the while loop, and doing something else.

This discussion is preserved as it was. New answers, comments, and votes are closed.