Brief description
I have tried to understand this for the past few mins but I was unable to understand it fully. This topic really confuses me a lot. I hope someone can explain it to me.
This is inside of a localscript. Basically I have a Value inside of a gui and then I pass that value to the FireServer parameter.
local buttons = {
["Add"] = Orbs:FindFirstChild("Add"),
["Title"] = Orbs:FindFirstChild("Confirm")
}
local debounce = false
local addValue = buttons.Add.Value
buttons.Confirm.MouseButton1Down:Connect(function()
OrbGiver:FireServer(v.Name -- each player, addValue.Value)
end)
Server script
OrbGiver.OnServerEvent:Connect(function(function(clientWhoFireEvent, targetPlayer, amount)
print(amount) -- Printed the amount passed in parameter (addValue.Value)
end)
Keep in mind the 1st parameter is always the player that fired the remote.
Even if you don’t state that the 1st parameter will always be the player that fired the remote.
So just add one more even if you’re not going to use who fired the remote at all.
example: money:FireServer(cash)
will come back as cash = 2112Jay and not be the cash amount I was looking for.
money:FireServer(player, cash) --Now cash will = cash
Hi, 2112Jay,
Thank you for your response. The issue I am trying to understand is why v.name which refers to each player on the server in the local script and addValue.Value, which refers to local player gui value.
For example,
Player 1 and player 2 are on the server. Player 1 fires the server event, and it will print the local player gui AddValue.Value amount (amount) which is from player 1 or the one who fired the event.
Hi 2112Jay,
Thank you for your response. If I had added that. V.name will now be each player but addValue.Value will be the local player gui value. So Im pretty confused especially if the server has lots of players
You would have to use the name to get that value from their GUI value for each one.
I assume you have a value set up in the players GUI you’re looking to use.
You’re not giving me much to work with here so this is just a guess at what you’re doing.
It may need some love …
local Orbs = -- your Orbs object
local OrbGiver = -- your OrbGiver object
local buttons = {
["Add"] = Orbs:FindFirstChild("Add"),
["Confirm"] = Orbs:FindFirstChild("Confirm")
}
local addValue = buttons.Add.Value
local db = true
buttons.Confirm.MouseButton1Down:Connect(function()
if db then db = false
for _, player in ipairs(game.Players:GetPlayers()) do
OrbGiver:FireServer(player.Name, addValue)
end db = true
end
end)
The lower part of the script is probably set up right, not sure about the rest …