Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

I don't know if this will work but try "game.LPlayer.leaderstats.laps.Value + 1" Notify me if that doesn't work..

0

That will not. Seriously Lua, what happened to the += operator....

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.