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

Transferring Variable through Remote Event?

I have a script in workspace and a localscript inside a GUI. The localscript fires a Remote Event and the script finds the fire. I want to transfer the variable Player (which is the player) from the LocalScript, onto the Script in workspace.

LocalScript:

local Player = game.Players.LocalPlayer

ClaimButton.MouseButton1Click:Connect(function()
	if Claimable.Value == true then
		print("fired")
		Client2Server.Claim:FireServer()
	else
		game.SoundService.Fart:Play()--Because why not?
	end
end)

Script:

local Claim = game.ReplicatedStorage.Client2Server.Claim


local ClaimList = {
	["Claim1"] = "";
	["Claim2"] = "";
	["Claim3"] = "";
	["Claim4"] = "";
	["Claim5"] = "";
	["Claim6"] = "";
	["Claim7"] = "";
	["Claim8"] = "";
	["Claim9"] = "";
	["Claim10"] = "";
	["Claim11"] = "";
	["Claim12"] = "";
	["Claim13"] = "";
	["Claim14"] = "";
	["Claim15"] = "";
	["Claim16"] = "";}
	
	
local TotalClaims = 0

Claim.OnServerEvent:Connect(function()
	print("we got it boys")
	for i,v in pairs(ClaimList)do
		print("in dat list")
		if v == "" then
			v = Player.Name
			print(Player,"is",v)
		end
	end
end)

It errors when it meets the Player Variable.

1 answer

✓ Accepted answer

The server will automatically detect the player who fired this remote event.

local Player = game.Players.LocalPlayer

ClaimButton.MouseButton1Click:Connect(function()
    if Claimable.Value == true then
        print("fired")
        Client2Server.Claim:FireServer(Player)
    else
        game.SoundService.Fart:Play()--Because why not?
    end
end)

This means in the server script, you will add one argument which is going to be the player

local Claim = game.ReplicatedStorage.Client2Server.Claim

local ClaimList = {
    ["Claim1"] = "";
    ["Claim2"] = "";
    ["Claim3"] = "";
    ["Claim4"] = "";
    ["Claim5"] = "";
    ["Claim6"] = "";
    ["Claim7"] = "";
    ["Claim8"] = "";
    ["Claim9"] = "";
    ["Claim10"] = "";
    ["Claim11"] = "";
    ["Claim12"] = "";
    ["Claim13"] = "";
    ["Claim14"] = "";
    ["Claim15"] = "";
    ["Claim16"] = "";}


local TotalClaims = 0

Claim.OnServerEvent:Connect(function(Player) --This argument is the player who fired this remote event
    print("we got it boys")
    for i,v in pairs(ClaimList)do
        print("in dat list")
        if v == "" then
            v = Player.Name
            print(Player,"is",v)
        end
    end
end)

I hope this helped, if it didn't please forgive me, I am not extremely professional myself.

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