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

How do we add a number to a String Value?

Asked by 4 years ago
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

0
I'm pretty sure you need an integer Value holamii2 45 — 4y
0
Try to do this on line 5: String.Value = String.Value + tostring("1"). Maybe that helps. Soban06 410 — 4y
0
Thx but It did't Help Xx0966xX 41 — 4y
0
Check out my answer! I hope it works for you! LittleGabieleRob 5 — 4y

4 answers

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

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)
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

Oh that is easy:

local str = "Hello"

str = str.."1"

print(str)
0
Bruh I need a Answer not someone to give Damp peace of code Xx0966xX 41 — 4y
Log in to vote
0
Answered by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.)

Answer this question