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

Making objects with filteringenabled?

I was wondering if it's possible to create an instance, say a part in a localscript and send the information of that Part to a serverscript with remoteevent or remotefunctions? Here's an example of what I'm talking about.

local x = Instance.new("Part")
x.BrickColor = BrickColor.new("Bright red")
x.Anchored = true
x.CanCollide = false
x.Size = Vector3.new(10,1,10)

game.Workspace.Scripts.CreateObjects.CreatePart:FireServer(x)

Is there a way to make it so the ServerScript receives the information to create x? I've tried this but it doesn't work.

function CreateItem(player,x)
x.Parent = game.Workspace
end

script.CreatePart.OnServerEvent:connect(CreateItem)

Is there any way to do this, without having to write down everything in the ServerScript? My reason for doing this is because I want to make it easier to find and fix/edit anything I make in the future without having a bunch of scripts and/or functions everywhere.

1 comment

0

Try parenting the part from the local script to lighting before you send it to the server script.

1 answer

✓ Accepted answer

Not like that.

x isn't replicated, so when Roblox sends its GUID across the network the function resolves the nonexistant Instance to nil. What you can do instead is try it so that you do

CreateObject:FireServer("Part", {
 Anchored = true;
 CanCollide = true;
 BrickColor = BrickColor.new("Bright red");
 Position = Vector3.new(10,1,10);
});

And then set everything on the server, like so:

CreateObject.OnServerEvent:connect(function(p,i,x)
 local i = Instance.new(i,workspace);
 for k,v in next, x do
  i[k] = v;
 end;
end)

EDIT: In retrospect, the server code would be better to set the Parent to workspace after setting the properties, so that events waiting for it fire properly.

CreateObject.OnServerEvent:connect(function(p,i,x)
 local i = Instance.new(i);
 for k,v in next, x do
  i[k] = v;
 end;
 i.Parent = workspace;
end)

1 comment

0

It worked, thank you.

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