Hei Developers
I recently watched some tutorials on Youtube about Sandbox Tycoons to introduce my knowledge to start creating for real, I learned to make the system of giving the player automatic plot, the placement, etc.
–total credits for zblox
However, I feel that my system is consuming a lot of memory, mainly because for each object I create, I need to put a script inside it
this is my current script in
StarterGUI> ScreenGui> LocalScript:
local player = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local player = player.LocalPlayer
local mouse = player:GetMouse()
local modules = replicatedstorage:WaitForChild("modules")
local models = replicatedstorage:WaitForChild("models")
local signals = replicatedstorage:WaitForChild("signals")
local remotes = signals:WaitForChild("remotes")
local functions = remotes:WaitForChild("functions")
local functionRF = functions:WaitForChild("requestPlacement")
local getPlot = functions:WaitForChild("requestPlot")
local placementModule = require (modules:WaitForChild("PlacementModuleV3"))
local placement = placementModule.new(
2,
models,
Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.U, Enum.KeyCode.J
)
local button = script.Parent.place
local plot = getPlot:InvokeServer()
local plotOBJ = plot.plot
local itemHolder = plot.ItemHolder
local function place(obj, stack, rot)
placement:activate(obj, itemHolder, plotOBJ, stack, rot)
end
button.MouseButton1Click:Connect(function()
place("part", true, false)
end)
mouse.Button1Down:Connect(function()
placement:requestPlacement(functionRF)
end)
saw that for each object I need this giant script … Is there any way to create a system where I create a value associated with the object? and how do I insert this into my script?
Thank you very much in advance
I didnt read the whole code but basically this piece of code will loop through all Objects and you can make them to work with one “script”
for example I want to get all objects in Workspace with name “TestObjects”
local WS = game:GetService("Workspace")
local CountOfChildrens = 0
for i,v in pairs(WS:GetChildren()) do --loop through all objects in workspace
if v.Name == "TestObjects" then --if Name is TestObjects then it will add +1 to Count of Children variable
CountOfChildrens += 1
end
print(CountOfChildrens) --number of childrens