I have a component system that requires all models that have a collection service tag and creates and gives the model the associated effects. What’s strange is that the same script works on the server but doesn’t on the client (in Replicated First. )
if not game:IsLoaded() then game.Loaded:Wait() end
local CollectionService = game:GetService("CollectionService")
function InitializeComponents(tag)
local component = script.Parent:FindFirstChild(tag)
print(`\n{component}`)
if component then
for _, instance in ipairs(CollectionService:GetTagged(tag)) do
require(component).new(instance)
end
CollectionService:GetInstanceAddedSignal(tag):Connect(function(newInstance)
require(component).new(newInstance)
end)
end
end
for _, tag in ipairs(CollectionService:GetAllTags()) do
print("\n"..tag)
InitializeComponents(tag)
end
But additionally it gives me feedback when I intentionally crash it.
This is very frustrating because I tested and have used the same script in other places, and it works in them, so it’s likely not to do with these scripts. But even after deleting almost everything it didn’t change. Heres a Link.rbxl (2.3 MB) to the file.
And all the instances that are being generated with a tag are on the client so it is mandatory that it’s client-sided .
tag Example #1
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Players = game:GetService("Players")
local Janitor = require(ReplicatedStorage.Modules.Janitor)
local Promise = require(ReplicatedStorage.Modules.Promise)
local FallingBrick = {}
function FallingBrick.new(model)
local self = setmetatable({
Janitor = Janitor.new()
}, {__index = FallingBrick})
print(model)
self.object = model
self.Janitor:Add(model, "Destroy")
self.Activated = false
self:Initialize()
return self
end
function FallingBrick:Initialize()
Janitor:Add(
self.object.Touched:Connect(function(instance)
if not self.object or self.Activated then return end
Promise.new(function(resolve, reject, onCancel)
local player:Player
Promise.try(function()
return Players:GetPlayerFromCharacter(instance.Parent) or Players:GetPlayerFromCharacter(instance.Parent.Parent) or instance
end):andThen(function(...)
player = ...
end)
:catch(function()
return nil
end)
if not player or not player:IsA("Player") then return end
--if onCancel(function() end) then return end
self.Activated = true
self.Janitor:Remove("Touched")
print(self.object.Anchored)
self.object.Anchored = false
self.object.CanCollide = false
print(self.object.Anchored)
resolve()
end):catch(function(err)
warn(err)
end)
end), "Disconnect", "Touched")
end
function FallingBrick:Destroy()
self.Janitor:Destroy()
setmetatable(self, nil)
table.clear(self)
end
return FallingBrick
tag Example #2
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Players = game:GetService("Players")
local Janitor = require(ReplicatedStorage.Modules.Janitor)
local Promise = require(ReplicatedStorage.Modules.Promise)
local HealBrick = {}
function HealBrick.new(model)
local self = setmetatable({
Janitor = Janitor.new()
}, {__index = HealBrick})
self.object = model
self.Janitor:Add(model, "Destroy")
self.debounce = {}
self:Initialize()
return self
end
function HealBrick:Initialize()
Janitor:Add(
self.object.Touched:Connect(function(instance)
if not self.object or self.object:GetAttribute("Damage") == 0 then return end
Janitor:AddPromise(Promise.new(function(resolve, reject, onCancel)
local player:Player
Promise.try(function()
return Players:GetPlayerFromCharacter(instance.Parent) or Players:GetPlayerFromCharacter(instance.Parent.Parent) or instance
end):andThen(function(...)
player = ...
end)
:catch(function()
return nil
end)
if not player or not player:IsA("Player") then return end
--if onCancel(function() end) then return end
if table.find(self.debounce, player.UserId) then return end
table.insert(self.debounce, player.UserId); Promise.delay(4.5):andThen(function()
table.remove(self.debounce, table.find(self.debounce, player.UserId))
end)
player.Character.Humanoid.Health =
math.clamp(math.abs(player.Character.Humanoid.Health + player.Character.Humanoid.MaxHealth)
, 1, player.Character.Humanoid.MaxHealth
)
resolve()
end):catch(function(err)
warn(err)
end) )--janitor
end), "Disconnect")
end
function HealBrick:Destroy()
self.Janitor:Destroy()
setmetatable(self, nil)
table.clear(self)
end
return HealBrick