Help with UI button and remote event

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Print the name of the button that fired a remote event
  2. What is the issue? Include screenshots / videos if possible!
    It prints username, instead of button name
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried moving around parameters and removing player from parameters etc

local function Vote(name)
    
    local name = script.Parent.name
    remoteEvent:FireServer(name)
end


-- Local ^^ Server Script VV


local voter = 0
local function VoteHandle(name)
    voter = voter + 1
    print(voter)
    print(name)
    
end
--Handle remote event etc

The first parameter of a remote event (on the server) will ALWAYS be the player… so it should look like this:

REMOTE_EVENT.OnServerEvent:Connect(function(player, button)--Player is always first.
 --do stuff here.
end)

NOTE: This is only the case for Client to server communication. Would not be like this for Server to client.

I recommend giving a read up on the wiki if you need anymore information. I can answer any questions you might have if you have any!

1 Like

I changed it to add player but I’m still getting the output of player name, not button name

local function Vote(name)
    
    local name = script.Parent.name
    remoteEvent:FireServer(name)
end


-- Local ^^ Server Script VV


local voter = 0
local function VoteHandle(name)
    voter = voter + 1
    print(voter)
    print(name)
    
end

In this script, name is defined as the player.
Write it as this:

local function Vote(name)
    
    local name = script.Parent.name
    remoteEvent:FireServer(name)
end


-- Local ^^ Server Script VV


local voter = 0
local function VoteHandle(player, name)
    voter = voter + 1
    print(voter)
    print(name)
    
end

Think of the first parameter of a RemoteEvent as it calling for the player who sent it.

1 Like

Thank you so much for this solution

You’re welcome! Have fun programming!

1 Like