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

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

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

local data = game:GetService("DataStoreService")
local datastore = data:GetDataStore("Milk")-- name of it
local datastore = data:GetDataStore("Coins")-- name of it
local rebirth = game.Workspace.Values.Rebirthmultiplier

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	
	local Milk = Instance.new("StringValue",Leaderstats)
	Milk.Name = "Milk"
	Milk.Value = 0
	
	local Coins = Instance.new("StringValue",Leaderstats)
	Coins.Name = "Coins"
	Coins.Value = 0
	
	function Call()
	local sell = Milk.Value
	Coins.Value = Coins.Value + Milk.Value
	Milk.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(player)
	datastore:SetAsync(player.UserId, player.leaderstats.Milk.Value)
	datastore:SetAsync(player.UserId, player.leaderstats.Coins.Value)
end)

game.Workspace.Sell.Sellpart.Touched:Connect(function(touched)
	Call()
end)

and

local Leaderstats = Instance.new("Folder")
local Milk = Instance.new("StringValue",Leaderstats)
local Coins = Instance.new("StringValue",Leaderstats)

script.Parent.Activated:Connect(function()
	Milk.Value = Milk.Value + 1
end)

1 answer

✓ Accepted answer

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:

local Milk = game:GetService("Players").LocalPlayer.Leaderstats.Milk.Value

script.Parent.Activated:Connect(function()
    Milk = Milk + 1
end)

Above is the local tool script.

local data = game:GetService("DataStoreService")
local datastore = data:GetDataStore("Milk")-- name of it
local datastore = data:GetDataStore("Coins")-- name of it
local rebirth = game.Workspace.Values.Rebirthmultiplier

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player

    local Milk = Instance.new("IntValue",Leaderstats)
    Milk.Name = "Milk"
    Milk.Value = 0

    local Coins = Instance.new("IntValue",Leaderstats)
    Coins.Name = "Coins"
    Coins.Value = 0

    function Call()
    local sell = Milk.Value
    Coins.Value = Coins.Value + Milk.Value
    Milk.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(player)
    datastore:SetAsync(player.UserId, player.leaderstats.Milk.Value)
    datastore:SetAsync(player.UserId, player.leaderstats.Coins.Value)
end)

game.Workspace.Sell.Sellpart.Touched:Connect(function(touched)
    Call()
end)

Above is a serverscript.

2 comments

0

like i said before when i replace them nothing happens

0

oof

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