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

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

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)

1 comment

0

Still need help with this!

1 answer

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^

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