Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Cuvette 246 Moderation Voter
9 years ago

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)
0
Replied. I would reply faster, but for some reason, I'm not getting a notification from this question, when you comment. Shawnyg 4330 — 9y
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. Cuvette 246 — 9y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

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.

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? Cuvette 246 — 9y
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! Shawnyg 4330 — 9y
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. Cuvette 246 — 9y
0
@Cuvette Hm, maybe Try remove the while loop, and doing something else. Shawnyg 4330 — 9y
Ad

Answer this question