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

Adding value script?

Asked by 10 years ago

So here's my script,

((Note, i did indent, the forums just weren't acting right))

function added(player)
    game.Players.LocalPlayer.PlayerGui.Backpack.Size = game.Players.LocalPlayer.PlayerGui.Backpack.Size.Value +1
end
game.Players.PlayerAdded:connect(added)

Now i need it to add +1 value?

I've tried

function added(player)
wait(10)
    game.Players.LocalPlayer.PlayerGui.Backpack.Size = game.Players.LocalPlayer.PlayerGui.Backpack.Size.Value +1
end
game.Players.PlayerAdded:connect(added)

Just for the sake of seeing if the size would +1.

If anyone can help, that be great.

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

In the assignment, you're saying

(...).Size = (...).Size.Value

You should be setting Size.Value on the left, not just Size.

In addition, you're using PlayerAdded but modifying the LocalPlayer. This means that whenever anyone else joins, you will add one point. A LocalScript doesn't load quickly enough that it can capture its own player joining, so nothing will happen if you just launch this.

0
I've tried that also, they both don't work. TwoSlhue 5 — 10y
0
Oh. You're right, I missed something else (this is also necessary). I updated the answer. BlueTaslem 18071 — 10y
0
Still confused.... TwoSlhue 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Blue was right. You have the variable 'player' for the Player that joined, then you went to use 'game.Players.LocalPlayer'. Also, you are making the 'Size' equal 'Size.Value' + 1, which should be 'Size.Value' being 'Size.Value' +1.

function added(player)
player.PlayerGui.Backpack.Size.Value = player.PlayerGui.Backpack.Size.Value +1
end
game.Players.PlayerAdded:connect(added)

That will fix the error in the script. However, you still have the issue of whatever 'Size' is not existing the exact moment that the Player joins. I honestly do not know what you are doing, here. You're adding 1 to the Value of 'Size' inside of something called 'Backpack' in the PlayerGui...but, why? You only want this to happen on the first time that they spawn? Because you are making this happen only once, when the Player joins the game.

0
Yes, this is for a DayZ Game that im helping develope, the backpack sizes are determined by the value of the gui. I'll try this and see. TwoSlhue 5 — 10y
0
All right. But, why are you adding '1' to the Value of 'Size' when they join, and only then? When they respawn, their PlayerGui will be emptied, and it will no longer increase by '1'. I'm just not sure why you're adding '1' whenever they join the game. You'll also probably want to wait for the Character to load before you do this. grimm343 30 — 10y

Answer this question