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

Help with Changed event and PlayerAdded?

Asked by 9 years ago
game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local level = Instance.new("IntValue", stats)
    level.Name = "Level"

    local exp = Instance.new("IntValue", stats)
    exp.Name = "Exp"

    local cash = Instance.new("IntValue", player)
    cash.Name = "Cash"

    local class = Instance.new("StringValue", player)
    class.Name = "Class"
    class.Value = "Laser"

    local team = Instance.new("StringValue", player)
    team.Name = "Team"
    team.Value = "White"

    player:WaitForDataReady()
    player.leaderstats.Level.Value = player:LoadNumber("Level")
    player.leaderstats.Exp.Value = player:LoadNumber("Exp")
    player.Cash.Value = player:LoadNumber("Cash")

    level.Changed:connect(function(level)
        print("Levelup")
        levelupframe:TweenPosition(UDim2.new(0.5, -150, 0.5, -50), "Out", "Quad", 1, false)
        leveluptext.Text =  "You have leveled up to Level: " .. level
        levelupframe.CashText.Text = "Cash + 50"
        wait("3")
        levelupframe:TweenPosition(UDim2.new(0, -300, 0.5, -50), "Out", "Quad", 1, false)
    end)
end)

I want have this so when a player joins it gets their values etc set up, but I want when they level up to print("Levelup") and show a a frame, There is no error, and it dosent print at all.

0
The extra lines are necessary. Unless there was another roblox update... EzraNehemiah_TF2 3552 — 9y
0
how though although they do is parent it, which is what ,stats does NinjoOnline 1146 — 9y

1 answer

Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

I noticed in the Changed event, there's already something called "level." Also, the Changed event returns the property that was changed. So, in order to get the new level, the code would be:

level.Changed:connect(function(property)
if property == "Value" then
print(level.Value)
end
end)

Since you used "level" in the parentheses instead of something different (I used "property"), maybe the reason the event doesn't fire could be because the item returned is the name of the item that is supposed to change. I know I didn't word this well, but I did my best. I can clarify in the comments.

0
Also, the last time I checked, the PlayerAdded event doesn't fire in solo mode. Maybe try changing that to ChildAdded. yumtaste 476 — 9y
0
PlayerAdded didn't used to fire, but it does now. It still doesn't work well in local scripts, however. Perci1 4988 — 9y
0
tried it still no success NinjoOnline 1146 — 9y
0
Ok. I'll keep looking for solutions yumtaste 476 — 9y
0
You should also tab your script. EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question