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

Can I pass Variables and its data from one server to another? (Local Script to Server Script))

so I basically want the player to trigger the event from the local script, then the server script will deliver the output instead of the local script so all players see the output... How do I do this? Is there another EASIER way to do it?

-Local Script-

local Tool = game.StarterPack.Wand
Tool.Equipped:Connect(function()
	Mouse.Button1Down:Connect(function()
		local BlockPlaced = 1
	Mouse.Button1Up:Connect(function()
		local BlockPlaced = 0

-Server Script-

--what do I do here?
if BlockPlaced == 1 then
	local clone = game.ReplicatedStorage.Part:Clone()
	clone.Parent = game.Workspace
	clone.Position = game.StarterPack.Wand.INVI.Position --INVI is a transparent block where I put cloned parts
	clone.Orientation = game.StarterPack.Wand.INVI.Orientation

1 answer

Yes there is a way easier way of doing this, and they're called RemoteEvents. They transfer data through things called arguments and parameters, it is the most efficient way of transferring data when going through Local Scripts and Server Scripts, for me.

Create a RemoteEvent in ReplicatedStorage. Then when you fire the event you're going to say :FireServer, and when you want to retrieve that broadcast, you access the same RemoteEvent from ReplicatedStorage and say .OnServerEvent. I will show you below.

--Say you have an Event in Replicated Storage named "Foxy"--

local Foxy = game:GetService('ReplicatedStorage'):FindFirstChild('Foxy')
local Tool = game.StarterPack.Wand
local BlockPlaced = 0
Tool.Equipped:Connect(function()
    Mouse.Button1Down:Connect(function()
        BlockPlaced = 1
	Foxy:FireServer(BlockPlaced)
    Mouse.Button1Up:Connect(function()
        local BlockPlaced = 0
	Foxy:FireServer(BlockPlaced)

Server

local Foxy = game:GetService('ReplicatedStorage'):FindFirstChild('Foxy')

Foxy.OnServerEvent:Connect(function(Player, BlockPlaced)
	if BlockPlaced == 1 then
		--do whatever happens when block is = to 1.
		if BlockPlaced == 1 then
   			 local clone = game.ReplicatedStorage.Part:Clone()
   			 clone.Parent = game.Workspace
   			 clone.Position = game.StarterPack.Wand.INVI.Position --INVI is a transparent block where I put cloned parts
    			clone.Orientation = game.StarterPack.Wand.INVI.Orientation
		
	else if BlockPlaced == 0 then
		--do whatever happens when block is = to 0. 
	end
end)

^ Assuming you send over the data for the StarterPack as well. Hope this helps!

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