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

string expected, got object help?

Asked by
NotSoNorm 777 Moderation Voter
9 years ago

So I keep getting the error, String expected, got object. Line 5: Bad argument #2 to '?'

NormalParts = {["Slab"] = true,["Wall"] = true,["Plate"] = true}
local event = script.BlockInsertation

event.OnServerEvent:connect(function(name)
local chil = game.Workspace[name]:GetChildren()
    for i, v in pairs (chil) do
        if NormalParts[v.Name] then
            local clone = workspace:FindFirstChild(name).Slab:Clone() or workspace:FindFirstChild(name).Wall:Clone() or workspace:FindFirstChild(name).Plate:Clone()
            clone.Parent = game.Workspace
        else
            script.Parent.MoneyDisplay.ErrorDisplay.Description.Text = "Undefined part value"
            script.Parent.MoneyDisplay.ErrorDisplay:TweenPosition(UDim2.new(0.8, 0,0.9, 0),"InOut","Linear",1,false)
            for i = 5, 1, -1 do
                wait(1)
                script.Parent.MoneyDisplay.ErrorDisplay.Timer.Text = i
            end
            script.Parent.MoneyDisplay.ErrorDisplay:TweenPosition(UDim2.new(1.3, 0,0.9, 0),"InOut","Linear",1,false)
            script.Parent.MoneyDisplay.ErrorDisplay.Timer.Text = "tim"
        end
    end
end)
0
Is FireServer being used in a LocalScript? Discern 1007 — 9y
0
yes NotSoNorm 777 — 9y
0
Wait a second, I have a question. Do you have to include the player parameter inside of the fireserver in the localscript? Frometa1998 35 — 5y

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago

I only looked at the first few lines of the script based on your error, so there may be another error later in the script.

The problem is that OnServerEvent takes two parameters. The first one MUST be the player, and the second is all the argument(s). You only have "name" which is what I'm assuming your argument. You just need to set player as a parameter.


Fixed Code:

NormalParts = {["Slab"] = true,["Wall"] = true,["Plate"] = true}
local event = script.BlockInsertation

event.OnServerEvent:connect(function(player, name) --The first parameter is the player, and the second one is all your arguments.
local chil = game.Workspace[name]:GetChildren()
    for i, v in pairs (chil) do
        for n, m in pairs(NormalParts) do
        if NormalParts[n] == v.Name then
            local clone = workspace:FindFirstChild(name).Slab:Clone() or workspace:FindFirstChild(name).Wall:Clone() or workspace:FindFirstChild(name).Plate:Clone()
            clone.Parent = game.Workspace
            break
        else
            script.Parent.MoneyDisplay.ErrorDisplay.Description.Text = "Undefined part value"
            script.Parent.MoneyDisplay.ErrorDisplay:TweenPosition(UDim2.new(0.8, 0,0.9, 0),"InOut","Linear",1,false)
            for i = 5, 1, -1 do
                wait(1)
                script.Parent.MoneyDisplay.ErrorDisplay.Timer.Text = i
            end
            script.Parent.MoneyDisplay.ErrorDisplay:TweenPosition(UDim2.new(1.3, 0,0.9, 0),"InOut","Linear",1,false)
            script.Parent.MoneyDisplay.ErrorDisplay.Timer.Text = "tim"
        end
        end
    end
end)

Here is the Wiki page on the event OnServerEvent.

If I helped you out, be sure to accept my answer!

0
If you get an error later in the script, then I will edit this answer. Discern 1007 — 9y
0
there isn't an error but at line 7 it chooses the else option even though the part is in there NotSoNorm 777 — 9y
Ad

Answer this question