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

im making a simulator and a part of the script wont work?

Asked by 4 years ago

its coming up with a error message saying " 20:50:56.931 - Players.cjkizzy286.Backpack.Milk.Script:6: attempt to perform arithmetic (add) on string and number" but if i change the value from a string to a int or number nothing happens the script wont run there are 2 bits of code

01local data = game:GetService("DataStoreService")
02local datastore = data:GetDataStore("Milk")-- name of it
03local datastore = data:GetDataStore("Coins")-- name of it
04local rebirth = game.Workspace.Values.Rebirthmultiplier
05 
06game.Players.PlayerAdded:Connect(function(Player)
07    local Leaderstats = Instance.new("Folder")
08    Leaderstats.Name = "leaderstats"
09    Leaderstats.Parent = Player
10 
11    local Milk = Instance.new("StringValue",Leaderstats)
12    Milk.Name = "Milk"
13    Milk.Value = 0
14 
15    local Coins = Instance.new("StringValue",Leaderstats)
View all 34 lines...

and

1local Leaderstats = Instance.new("Folder")
2local Milk = Instance.new("StringValue",Leaderstats)
3local Coins = Instance.new("StringValue",Leaderstats)
4 
5script.Parent.Activated:Connect(function()
6    Milk.Value = Milk.Value + 1
7end)

1 answer

Log in to vote
1
Answered by 4 years ago

You are using StringValues, therefore you can't use the add function. Make sure you keep it IntValue. Plus, you don't need to create another Instance of the leaderstats in the tool script. This is what your scripts should look like:

1local Milk = game:GetService("Players").LocalPlayer.Leaderstats.Milk.Value
2 
3script.Parent.Activated:Connect(function()
4    Milk = Milk + 1
5end)

Above is the local tool script.

01local data = game:GetService("DataStoreService")
02local datastore = data:GetDataStore("Milk")-- name of it
03local datastore = data:GetDataStore("Coins")-- name of it
04local rebirth = game.Workspace.Values.Rebirthmultiplier
05 
06game.Players.PlayerAdded:Connect(function(Player)
07    local Leaderstats = Instance.new("Folder")
08    Leaderstats.Name = "leaderstats"
09    Leaderstats.Parent = Player
10 
11    local Milk = Instance.new("IntValue",Leaderstats)
12    Milk.Name = "Milk"
13    Milk.Value = 0
14 
15    local Coins = Instance.new("IntValue",Leaderstats)
View all 34 lines...

Above is a serverscript.

0
like i said before when i replace them nothing happens cjkizzy286 40 — 4y
0
oof R_LabradorRetriever 198 — 4y
Ad

Answer this question