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

Sending Table of Instances using FireServer/RemoteEvent?

So I'm trying to make my scripting more efficient but I've come up w/ a problem. I don't know how to really explain my problem other than wanting to send multiple instances exactly how I make them in the following code:

Local x = Instance.new("Part")
x.BrickColor = BrickColor.new("CGA Brown")
x.Material = "Neon"
x.Reflectance = 0
x.Transparency = 0.5
x.Name = "Fireball"
x.Anchored = false
x.CanCollide = false
x.Locked = true
x.Shape = "Ball"
x.Size = Vector3.new(5,5,5)
x.TopSurface = "SmoothNoOutlines"
x.BottomSurface = "SmoothNoOutlines"
x.FrontSurface = "SmoothNoOutlines"
x.BottomSurface = "SmoothNoOutlines"
x.RightSurface = "SmoothNoOutlines"
x.LeftSurface = "SmoothNoOutlines"

local bv = Instance.new("BodyVelocity")
bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = torso.CFrame.lookVector*50
bv.Parent = x

local f = Instance.new("Fire")
f.Color = Color3.new(255/255,170/255,0/255)
f.SecondaryColor = Color3.new(255/255,255/255,255/255)
f.Heat = 25
f.Size = 10
f.Parent = x

x.Parent = game.Workspace
x.CFrame = torso.CFrame*CFrame.new(0,0,-10)

Is there a way to send the information for x, or x to the remoteevent and have it create x?

1 answer

✓ Accepted answer

If the server creates those objects, it can simply send a reference to them to the client (though they need to have a parent first, I think). If you don't want them in the workspace, you should be able to put them in ReplicatedStorage. (After transmitting with a reference to the object, maybe after a wait(), you can then remove the object from ReplicatedStorage if you don't need it anymore.)

If it's the client that is creating the objects (in a place with FilteringEnabled on), you will have to convert each object into a list of strings/numbers. If you can use this code to initialize the object instead...

local data = {
	Type = "Part",
	Properties = {
		BrickColor = BrickColor.new("CGA Brown"),
		Material = "Neon",
		--etc
	},
	Children = {
		{
			Type = "BodyVelocity",
			Properties = {
				--fill this in
		},
		--next child here
	},
}

...then it is easy to generate these objects on the server after transmitting 'x'

function GenerateObject(data)
	local obj = Instance.new(data.Type)
	for prop, value in pairs(data.Properties) do
		obj[prop] = value
	end
	if data.Children then
		for i = 1, #data.Children do
			GenerateObject(data.Children[i]).Parent = obj
		end
	end
	return data
end

But this is not secure. Theoretically, a hacker/exploiter may be able to transmit whatever they want from the client to the server, which would effectively let them create any object they like (though they might not be able to load a functional script).

Instead, it makes more sense to generate the object(s) on the server. Monitor the events that cause the object(s) to be generated on the server as much as possible, transmitting information from the client as needed. In general, try to trust the client as little as possible.

If you already have the instances, you could use a function to convert them into the data format above (and then the rest is the same).

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