More Efficient Scripting (Local to Server script Remote Events) [SOLVED]

the tools are called “Comic1Tool, Comic2Tool” etc and the remote events are “CopyComic1P1, CopyComic1P2” etc. As in copying Comic1 to Part 1, thats why i named the events like that.

Change the line into this and when firing the event send Mouse.Target.Name as an argument

local ComicTool = ReplicatedStorage.Tools:FindFirstChild(ToolName)

Im not exactly sure how to send it as an argument :confused: would it be like inside the of FireServer() ?

Yeah, FireServer(Mouse.Target.Name)

ok i did both but now the error i get is “Argument 1 missing or nil - Server - ComicPlacement1Script:8”

oh and line 8 is

		local ComicTool = reptools:FindFirstChild(ToolName)

On the server event do

v.OnServerEvent:Connect(function(Player, ToolName) – Tool name is the argument we sent

Ok so my local script looks like this now

local rep = game:GetService("ReplicatedStorage").POVComps.BBComics.CopyComicPlacements
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()

function onButton1Down(Player)
	for i = 1, 16 do
		if mouse.Target.Name == ("ComicPlacement" .. i) then
			rep["CopyComic1P" .. i]:FireServer(mouse.Target.Name)
			print("Copying Comic 1 to Placement " .. i)
			break
		end
	end
end
mouse.Button1Down:Connect(onButton1Down)

And my server script is

local repplcmt = game:GetService("ReplicatedStorage").POVComps.BBComics.CopyComicPlacements
local reptools = game:GetService("ReplicatedStorage").POVComps.BBComics.ComicTools
local ComicPlacement = script.Parent

for _, v in pairs(repplcmt:GetChildren()) do
	v.OnServerEvent:Connect(function(Player,ToolName)
		print("Event fired")
		local ComicTool = reptools:FindFirstChild(ToolName)
		ComicTool.Parent = game.Workspace
		ComicTool.Handle.CFrame = ComicPlacement.CFrame
		ComicTool.Handle.Anchored = true
	end)
end

but the error i get is “Argument 1 missing or nil - Server - ComicPlacement1Script:8”

Which line of code is line 8??

it is

		local ComicTool = reptools:FindFirstChild(ToolName)

Does the parts your clicking on and the tools in your tools folder have the same name?

no, the tools are called “Comic1Tool” and the parts are called “ComicPlacement1” and theres 16 of each total.

On the local script before firing the event do this

local ToolName = tostring(“Comic”…string.sub(Mouse.Target.Name, -1, -1)…“Tool”)
rep[“CopyComic1P” … i]:FireServer(ToolName)

1 Like

It worked! But how would I also use this for my other tools/parts? Would I just copy paste them?

This code here gets the number from the part your clicking on so it should work for everything

local ToolName = tostring(“Comic”…string.sub(Mouse.Target.Name, -1, -1)…“Tool”)

I trie duploading a video to show the issue but here, this is what happens now that I have the scame scripts for my 2nd tool and 2nd part to place the tool. It works but it initially copies it on the wrong part, not the one I clicked on.

In this script what is CosmicPlacement? is it a Position? a CFrame?

local repplcmt = game:GetService(“ReplicatedStorage”).POVComps.BBComics.CopyComicPlacements
local reptools = game:GetService(“ReplicatedStorage”).POVComps.BBComics.ComicTools
local ComicPlacement = script.Parent

for _, v in pairs(repplcmt:GetChildren()) do
v.OnServerEvent:Connect(function(Player,ToolName)
print(“Event fired”)
local ComicTool = reptools:FindFirstChild(ToolName)
ComicTool.Parent = game.Workspace
ComicTool.Handle.CFrame = ComicPlacement.CFrame
ComicTool.Handle.Anchored = true
end)
end

ComicPlacement is the name of the part that when clicked on, copies the tool over into the workspace to be the same position. Its the gray empy rectangle on the right side of the screen i click on in the video.

Do each of these parts have the exact same script?

Sorry I was trying to see what to edit in the script myself but yeah they script is the same in both “ComicPlacement1” and “ComicPlacement2” parts.