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

How would I add to a value to make a current one increase?

Asked by 4 years ago

I tried making a script but I only know how to set a value for example = 1 not make it increase

This is my code:

if script.Parent.Touched:Connect(function()

    local LPlayer = game.Players.LocalPlayer.Name

    game.LPlayer.leaderstats.laps.Value = +1

end)
0
I don't know if this will work but try "game.LPlayer.leaderstats.laps.Value + 1" Notify me if that doesn't work.. MajenBej 5 — 4y
0
That will not. Seriously Lua, what happened to the += operator.... Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It looks like you're a beginner scripter, so try learning the basics and then go on and study events. But anyway, to answer the question, you have to say LPlayer.leaderstats.laps.Value = LPlayer.leaderstats.laps.Value + 1. This basically means value is equal to value plus 1. Also, you don't have to say game.LPlayer since it's a variable. Below is what the full script would look like.

script.Parent.Touched:Connect(function(hit)

    local LPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

    LPlayer.leaderstats.laps.Value =  LPlayer.leaderstats.laps.Value + 1

end)

You should remove the if in if script.Parent.Touched:Connect(function() since it would error. And finnaly, you shouldn't use game.Players.LocalPlayer in a ServerScript, as it would return nil. Please try doing more research on Roblox Lua before asking.

Ad

Answer this question