Hello everyone!
I was making a tower climbing based game where you have Client Objects that are only interactable with the player inside a certain Tower. First, the game takes away the client objects from the towers in a server script by reparenting them to a folder called COfolder in replicated storage. Inside that folder are folders with the names of the towers (For example there would be a "Tower of Mess Ups" folder in there, because it is a tower). Here is the script (Note that it is inside another script called "TowerAdjusts". The "TowerAdjusts" script puts the scripts inside them into all the folders of the towers in the game):
IsInTower = script.Parent.Name ~= "TowerAdjusts"
if IsInTower then
AllCOs = script.Parent.ClientSidedObjects:GetChildren()
COfolder = game.ReplicatedStorage:FindFirstChild("COfolder")
if not COfolder then
COfolder = Instance.new("Folder", game.ReplicatedStorage)
COfolder.Name = "COfolder"
end
TowerFolder = Instance.new("Folder", COfolder)
TowerFolder.Name = script.Parent.Name
for i = 1, #AllCOs do
CO = AllCOs[i]
CO.Parent = TowerFolder
end
end
Next, when a player enters a tower, an event fires from a server script inside a block called "Detection". Here is a script from "Tower of Mess Ups" detection block (All are the same for all towers in the game, except different parameters are being passed depending on the tower):
active = false
script.Parent.Touched:Connect(function(t)
if t.Parent:FindFirstChild("HumanoidRootPart") then
if active == false then
game.ReplicatedStorage.COspawner:FireClient(game.Players:GetPlayerFromCharacter(t.Parent), "Tower of Mess Ups")
active = true
wait(0.5)
active = false
end
end
end)
Then, a player script (One I put in "StarterPlayerScripts") takes the event fired and put the COs in the respective folder of the tower the player went into. Here is that script:
game.ReplicatedStorage.COspawner.OnClientEvent:Connect(function(Tower)
local tower = game.Workspace.Towers:FindFirstChild(Tower)
local COtowerFolder = game.ReplicatedStorage.COfolder:FindFirstChild(Tower)
local allCOs = COtowerFolder:GetChildren()
for i = 1, #allCOs do
local CO = allCOs[i]
local COclone = CO:Clone()
COclone.Parent = tower:FindFirstChild("ClientSidedObjects")
end
end)
This method succeeds in reparenting the COs, but scripts placed in the COs will not run at all (They are all module scripts). I know that my method is flawed, but I don't know in what way, therefore I cannot fix it. May someone please tell me where I went wrong with this?
Any help is appreciated, thanks! :D
