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

How can I send a variable from a local script to a server script with FE enabled?

Asked by 5 years ago

Hey there, I am trying to send a variable called "PLK" from a localscript to a server script. Currently in Experimental mode, _G is working, however when filtering is enabled, this no longer works for client to server communication. How can I send the variable over?

script.Parent.BREAKFAST.MouseButton1Click:connect(function()
    local breakfastevent = script.Parent:WaitForChild("Value").Value:WaitForChild("breakfastEvent")
_G.plk = String.Value
   breakfastevent:FireServer()

end)

Local Script^

breakfast.OnServerEvent:connect(function()
    local Target = _G.plk
    local meals = game.Players:WaitForChild(Target, 15):WaitForChild("MEALS")
    local player = game.Players:WaitForChild(Target)
    if meals.Breakfast.Waffles.Value == true then
        local waffles = game.ServerStorage:WaitForChild("WaffleBreakfast"):Clone()
        waffles.Parent = player.Backpack
    elseif meals.Breakfast.Bacon.Value == true then
        local bacon = game.ServerStorage:WaitForChild("BaconEggBreakfast"):Clone()
        bacon.Parent = player.Backpack
    elseif meals.Breakfast.Omlette == true then
        local omlette = game.ServerStorage:WaitForChild("OmletteBreakfast"):Clone()
        omlette.Parent = player.Backpackwww
    end
end)

Server Script^

(This is eventually going to be used to serve food in a restaurant)

0
Still need help with this! healthymoses6 5 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Whenever a remote event is fired by the client, an argument is sent to the server that is the player object. You don't even need any variable for this to work

script.Parent.BREAKFAST.MouseButton1Click:connect(function()
    local breakfastevent = script.Parent:WaitForChild("Value").Value:WaitForChild("breakfastEvent")
   breakfastevent:FireServer()
end)

Local Script^

breakfast.OnServerEvent:connect(function(Target) -- Target is the player object
    local meals = game.Players:WaitForChild(Target.Name, 15):WaitForChild("MEALS") -- Had to change to Target.Name
    local player = game.Players:WaitForChild(Target.Name) -- Had to change to Target.Name
    if meals.Breakfast.Waffles.Value == true then
        local waffles = game.ServerStorage:WaitForChild("WaffleBreakfast"):Clone()
        waffles.Parent = player.Backpack
    elseif meals.Breakfast.Bacon.Value == true then
        local bacon = game.ServerStorage:WaitForChild("BaconEggBreakfast"):Clone()
        bacon.Parent = player.Backpack
    elseif meals.Breakfast.Omlette == true then
        local omlette = game.ServerStorage:WaitForChild("OmletteBreakfast"):Clone()
        omlette.Parent = player.Backpackwww
    end
end)

Server Script^

Ad

Answer this question