Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Transferring Variable through Remote Event?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question