Function takes values the opposite way

Hey, I have another silly question, I have a function that changes values server sided but for some example it does it the wrong way

This is the local script:

local bidValue = ReplicatedStorage:WaitForChild("HighestBid")
local bid = localBid
local bidder = player.Name
remoteEvent:FireServer(bid, bidder)

This is the server script:

local bidValue = ReplicatedStorage:WaitForChild("HighestBid")
local bidderValue = ReplicatedStorage:WaitForChild("HighestBidder")

local function changeValues(bid, bidder)
	bidValue.Value = bid
	bidderValue.Value = bidder
	
	highestBid.Text = tostring(bid)
	highestBidder.Text = bidder
end

But this is what it gives me:
image
image
HighestBidder is meant to be a name, and highestbid is meant to be the 124
It is probably another stupid mistake I made but I can not seem to find it, does anyone know why this happens??

1 Like

The list of arguments for a server-sided listener looks like this:

PlayerClientThatFiredServer, arg1, arg2, .... argn

When you fire the server with your remoteEvent, bid gets assigned the player who fired the event and bidder is assigned the bid. In short, that’s why it reverses.

If you need to keep both of those arguments and the player argument can’t replace bidder, do

remoteEvent:FireServer(bidder, bid)

Otherwise if the player argument IS the bidder you wanted anyways, you can just simply do
remoteEvent:FireServer(bid)

The bidder will automatically be the first argument of your listening function on the server side.

I just changed remoteEvent:FireServer(bid, bidder) to remoteEvent:FireServer(bidder, bid) and also changed it for the function to (bidder, bid) but now it doesn’t change the bid value, the bid value stays at 0, but it does change the bidder name to the player name

Also in the Bindable Events and Functions | Roblox Creator Documentation page it does not say anything about of the arguments work like the way you said it, it gives an example of, remoteEvent:FireServer(BrickColor.Red(), Vector3.new(0, 25, 0))

What is localbid defined as? Are you sure you’re sending the numerical value of the bid and not the NumValue object itself?

localbid is, localBid = tonumber(bidBox.Text)

Also yes it does define it that way, please refer to RemoteEvent.OnServerEvent. I worded it differently but the first argument is always the firing player.

1 Like

This is because the first argument of OnServerEvent is always the Player object who fired the event, as @Tyler148 mentioned.

remoteEvent.OnServerEvent:Connect(function(player, bid, bidder)
	changeValues(bid,bidder)
end)

Honestly you could lose the ‘bidder’ variable entirely and just derive it from the player’s name server side

bidder = player.Name

This still does not solve the problem of the HighestBid value not changing when the event fires but thank you

Are both ‘HighestBidder’ and ‘HighestBid’ both NumberValue objects?

If so you cannot store a string value (player.Name) to a NumberValue.
Create a new ‘HighestBidder’ object from a StringValue

HighestBidder is a string object and it works, HighestBid is a number object but it does not work

Also on the GUI where it is meant to set the highest bid to the number it sets it to the bidder
image

That’s odd.

Can you show us your OnServerEvent and how it invokes changeValues on the server?

Also, print out the ‘bid’ and ‘bidder’ values before FireServer on the client just to double check these values have something.

When I print the bid value in the local script, it prints the value that I put in but in the server script it prints out my username and does not change the value

This is the whole server script,

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("AuctionBidEvent")

local gui = script.Parent
local highestBid = script.Parent.MainFrame.BidFrame.BidAmount
local highestBidder = script.Parent.MainFrame.BidFrame.BidName

local bidValue = ReplicatedStorage:WaitForChild("HighestBid")
local bidderValue = ReplicatedStorage:WaitForChild("HighestBidder")

local function changeValues(bidder, bid)
	bidValue.Value = bid
	bidderValue.Value = tostring(bidder)
	
	highestBid.Text = tostring(bid)
	highestBidder.Text = tostring(bidder)
end

remoteEvent.OnServerEvent:Connect(changeValues)

Yes this makes sense now. As we’ve both said - ‘bidder’ is the Player object (A0RK0)

This means, ‘bid’ is now also the Name value you passed through “A0RK0”

So when you set bidderValue, you’re converting the PlayerObject to a string “A0RK0”

Apply this change

local function changeValues(player,bidder,bid)

This happens because OnServerEvent automatically populates the FIRST parameter with the player who FiredServer.

1 Like