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

How do we add a number to a String Value?

local String = game.ReplicatedStorage.StValue -- StValue is my StringValue 

Game.Players.PlayerAdded:Connect(Funcation() -- I want to add 1 evrey time a player 	Joined

	String.Value = String.Value + "1" -- Am I doing anything Wrong here?


end)

Am getting this Message in the out put

ServerScriptService.Script:9: attempt to perform arithmetic (add) on Instance and string

4 comments

0

I'm pretty sure you need an integer Value

0

Try to do this on line 5: String.Value = String.Value + tostring("1"). Maybe that helps.

0

Thx but It did't Help

0

Check out my answer! I hope it works for you!

4 answers

✓ Accepted answer

Use an Integer Value instead of a String, String Values are for text. But if you want it to add 1 to the text do this:

local String = game.ReplicatedStorage.StValue 

Game.Players.PlayerAdded:Connect(function() 

    String.Value = String.Value.."1"

end)

If you want to convert an IntValue into a StringValue do this:

local Integer = game.ReplicatedStorage.IntValue 

Game.Players.PlayerAdded:Connect(function() 

    Integer.Value = Integer.Value + 1

local string = tostring(Integer.Value)

end)

Oh that is easy:

local str = "Hello"

str = str.."1"

print(str)

1 comment

0

Bruh I need a Answer not someone to give Damp peace of code

You should use an IntValue for this, not a String Value

Hey, I see a misspelling here! Correction:

Game.Players.PlayerAdded:Connect(function()
--In this part, you want to have a NumberValue with you.
Number.Value = Number.Value + 1
String.Value = Number.Value
end)

Test this out and let me know if it works! (No bad comments, please.)

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