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

How to auto update this Code?

Asked by 9 years ago

I know that this is for when a player enters; but i cant seem to get it to automatically update for my RPG. Basically the GUi above the players head will show his level, and when he levels up the gui should update, but idk how to put this into the code without it messing up the parameters:

game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
    wait(1)

        gui=Instance.new("BillboardGui")
        gui.Parent=newPlayer.Character.Head
        gui.Adornee=newPlayer.Character.Head
        gui.Size=UDim2.new(3,0,3,0)
        gui.StudsOffset=Vector3.new(0,2,0)
        local text1=Instance.new("TextLabel")
        text1.Text = ("Level:"..newPlayer.leaderstats.Lvl.Value)
        text1.FontSize = "Size14"
        text1.TextColor3 = Color3.new(170, 0, 0)
        text1.TextStrokeColor3 = Color3.new(0, 0, 0)
        text1.TextStrokeTransparency = 0
        text1.Size=UDim2.new(1,0,1,0)
        text1.Position=UDim2.new(0,0,0,0)
        text1.BackgroundTransparency = 1
        text1.Parent=gui
end

function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)


thanks ~ bubs

1 answer

Log in to vote
2
Answered by 9 years ago

You seem to have a 'non-perfect' event ;p

The '.Changed' should only be used when there aren't any events for that case. In this case, we got an event called 'CharacterAdded'

Let's change the code:

newPlayer.Changed(...)

-- Delete that. :)

Now we need to make it actually connect the event, so we got the final code of:

game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
    wait(1)

        gui=Instance.new("BillboardGui")
        gui.Parent=newPlayer.Character.Head
        gui.Adornee=newPlayer.Character.Head
        gui.Size=UDim2.new(3,0,3,0)
        gui.StudsOffset=Vector3.new(0,2,0)
        local text1=Instance.new("TextLabel")
        text1.Text = ("Level:"..newPlayer.leaderstats.Lvl.Value)
        text1.FontSize = "Size14"
        text1.TextColor3 = Color3.new(170, 0, 0)
        text1.TextStrokeColor3 = Color3.new(0, 0, 0)
        text1.TextStrokeTransparency = 0
        text1.Size=UDim2.new(1,0,1,0)
        text1.Position=UDim2.new(0,0,0,0)
        text1.BackgroundTransparency = 1
        text1.Parent=gui
end

function onPlayerEntered(newPlayer)
    --[[newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)]]--
    newPlayer.CharacterAdded:connect(function(char)
            onPlayerRespawned(newPlayer)
    end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)



But now we face a dillema: WE WANT IT TO AUTO UPDATE!

For this, make a new LocalScript in Backpack. Now change this to the code:

function onPlayerUpdate()
    wait(1)

        if (game:service('Players').LocalPlayer.Character:FindFirstChild('Head')~=nil) then
        if (game:service('Players').LocalPlayer.Character.Head:FindFirstChild("BillboardGui")==nil then
        gui=Instance.new("BillboardGui")
        gui.Parent=game:service('Players').LocalPlayer.Character.Head
        gui.Adornee=game:service('Players').LocalPlayer.Character.Head
        gui.Size=UDim2.new(3,0,3,0)
        gui.StudsOffset=Vector3.new(0,2,0)
        local text1=Instance.new("TextLabel")
        text1.Text = ("Level:"..game:service('Players').LocalPlayer.leaderstats.Lvl.Value)
        text1.FontSize = "Size14"
        text1.TextColor3 = Color3.new(170, 0, 0)
        text1.TextStrokeColor3 = Color3.new(0, 0, 0)
        text1.TextStrokeTransparency = 0
        text1.Size=UDim2.new(1,0,1,0)
        text1.Position=UDim2.new(0,0,0,0)
        text1.BackgroundTransparency = 1
        text1.Parent=gui else
        game:service('Players').LocalPlayer.Character.Head.BillboardGui.TextLabel.Text= ("Level:"..game:service('Players').LocalPlayer.leaderstats.Lvl.Value)
        end end
end

while true do
onPlayerUpdate()
wait(.1)
end

Also make sure you make the LocalScript...

Thanks! ~marcoantoniosantos3

0
Thanks a lot! But does this mean that other players will be able to see it? (Because it's a local script) ? Bubbles5610 217 — 9y
0
Other players will be able to see it as long as you don't have filtering enabled Thewsomeguy 448 — 9y
0
How can I make sure filtering is off? Or is it off by default ? Bubbles5610 217 — 9y
0
Umm how do i make a new LocalScript in Backpack? Bubbles5610 217 — 9y
0
Filtering is off by default, and to make a localscript in backpack just make it in the StarterPack while in edit mode! marcoantoniosantos3 200 — 9y
Ad

Answer this question