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

bad argument #2 to expected, got object Please Help?!? (SOLVED)

localscript

local thevalue = script.Parent.Parent.MoneyPValue
local remotevalue = script.Parent.Parent.MoneyRemoteValue

script.Parent.MouseButton1Down:Connect(function()
	remotename:FireServer(thevalue.Text)
end)

script

local remotepvalue = script.Parent.MoneyRemoteValue
local themoneyvalueis = script.Parent.MoneyValue

local function theplayervalueis(player, MoneyPValue)
	themoneyvalueis.Value = MoneyPValue --it doesn't change the value and it says "bad argument #2 to expected, got object"
end

remotepvalue.OnServerEvent:Connect(theplayervalueis)

So my Problem here is. If I press the button it doesn't change the value and it prints and error which says "bad argument #2 to expected, got object" Please Help!

1 answer

Two problems that your scripts have are that in your local script you are sending the NumberValue object rather than the NumberValue.Value, and in the script you aren't accounting for the player argument that gets passed in to OnServerEvent by default. Try something like this:

Local Script

local theValue = script.Parent.Parent.MoneyPValue
local remoteValue = script.Parent.Parent.MoneyRemoteValue

script.Parent.MouseButton1Down:Connect(function()
	remoteValue:FireServer(theValue.Value) -- Need to send the .Value, not the value object
end)

Script

local remotePValue = script.Parent.MoneyRemoteValue
local theMoneyValueIs = script.Parent.MoneyValue

-- OnServerEvent gets passed the player that called it as the first argument
local function ThePlayerValueIs(player, moneyPValue)
	theMoneyValueIs.Value = moneyPValue
end

remotePValue.OnServerEvent:Connect(ThePlayerValueIs)

11 comments

0

doesn't work :C

0

also sorry i didn't say that the theValue is TextBox So it will be theValue.Text But Doesn't WOrk!

0

You need to provide more info than that. What is happening - are you getting an error? And if so, what does it say?

0

it says the same thing! "bad argument #2 to expected, got object" but i don't have error on the code!

0

what line is the error on? and in the local script or the server script?

0

script it doesn't change the value!

0

Edit your question above with how your scripts look now so that I can see where the error might be

0

If the money value is a number in a text label, try using tonumber().

0

vector3_zero Done!

0

Can you throw a 'print(moneyPValue)' in the server script between lines 5 and 6 and reply with what it prints out?

0

wait its fixed... lol

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