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

Bad argument #2 (string expected, got Object) ?

local ServerStorage = game:WaitForChild("ServerStorage")
local Ogetti = ServerStorage:WaitForChild("Oggetti")
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Items = workspace:WaitForChild("Items")

local ServerStorage = game:GetService("ServerStorage")

local function bring(posizione,oggetto)
	print(posizione,oggetto)
	local ogg = ServerStorage.Oggetti[oggetto]:Clone()
	print(ogg)
end

local function Prendi()
	local s = Ogetti:GetChildren()
	local f = s[math.random(1, #s)]
	return f
end

local function spawns()
	for i,v in pairs(Items:GetChildren()) do
		if v.Name == "Oggetto" then
			local a = Prendi()
			print(v,a)
			bring(v,a)
		end
	end	
end

wait(game)
spawns()

i have this error inside the function "bring", at the "local ogg". Inside my game i have a Folder inside ServerStorage (called "Oggetti") and inside that folder there are some stuff. (Parts)

P.s. sorry for bad english

1 comment

0

Youve already referenced serverstorage at line 1 so change line 2 serverstorage to game

1 answer

✓ Accepted answer

It's because Oggetti itself is not a string, and you can't print things that aren't strings. So you need to get Oggetti's name. Also, there are some other things were you need to use name too. Here is the script:

local ServerStorage = game:WaitForChild("ServerStorage")
local Ogetti = ServerStorage:WaitForChild("Oggetti")
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Items = workspace:WaitForChild("Items")

local ServerStorage = game:GetService("ServerStorage")

local function bring(posizione,oggetto)
    print(posizione,oggetto.Name)
    local ogg = ServerStorage.Oggetti[oggetto]:Clone()
    print(ogg.Name)
end

local function Prendi()
    local s = Ogetti:GetChildren()
    local f = s[math.random(1, #s)]
    return f
end

local function spawns()
    for i,v in pairs(Items:GetChildren()) do
        if v.Name == "Oggetto" then
            local a = Prendi()
            print(v.Name,a)
            bring(v.Name,a)
        end
    end 
end

wait(game)
spawns()

I hope this helped! Edit: posizione is position right? If yes, then we don't need to use their names.

2 comments

0

Thank you ^^

0

No problem.

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