I am working on a modular cafe system for a game I am working on. It uses a custom cape system that I created which allows a user with permissions to give themselves a cape and change the texture to an image on roblox(creator marketplace). I have done everything correctly and there are no errors in the code. However, the code hangs after preloading the texture. The texture shows up just fine and the cape works as intended, however, the code after the preload does run at all and that causes the systems using cape to break and not function properly. Down bellow is the code. The snipped that involves printing not finished is to see how long it takes before PreloadAsync’s callback function to be ran. The last test I ran on this code resulted in me stopping the test after 158 seconds of waiting with no result. What am I doing wrong?
function CapeSystem:new(plr,data)
local texture
if data then
texture = data.Texture or self.ImageID
else
texture = self.ImageID
end
local Beam
local Character = plr.Character
local CapeTop = Instance.new("Part",Character)
local CapeBottom = Instance.new("Part",Character)
local CapeTopAttachment1 = Instance.new("Attachment",Character:WaitForChild("UpperTorso"))
local CapeTopAttachment2 = Instance.new("Attachment",Character:WaitForChild("UpperTorso"))
local CapeHeadAttachment = Instance.new("Attachment",CapeTop)
local CapeBottomAttachment = Instance.new("Attachment",CapeBottom)
Beam = Instance.new("Beam",CapeTop)
local AllignOrientation = Instance.new("AlignOrientation",CapeBottom)
local AllignPosition = Instance.new("AlignPosition",CapeBottom)
local AllignOrientation = Instance.new("AlignOrientation",CapeBottom)
local BodyGyro = Instance.new("BodyGyro",CapeBottom)
local RigidConstraint = Instance.new("RigidConstraint",CapeTop)
CapeTop.Name = "CapeTop"
CapeBottom.Name = "CapeBottom"
CapeTopAttachment1.Name = "CapeBottomAttachment"
CapeTopAttachment2.Name = "CapeTopAttachment"
CapeHeadAttachment.Name = "CapeHeadAttachment"
CapeBottomAttachment.Name = "CapeBottomAttachment"
CapeTop.Size = Vector3.new(.1,.1,.1)
CapeBottom.Size = Vector3.new(.1,.1,.1)
CapeTopAttachment1.Position = Vector3.new(0, -2.5, 1.5)
CapeTopAttachment1.Orientation = Vector3.new(0,0,90)
CapeTopAttachment2.Position = Vector3.new(0, .8, 0.5)
CapeTopAttachment2.Orientation = Vector3.new(0,0,90)
CapeBottomAttachment.Position = Vector3.new(0,0.125,0)
CapeBottomAttachment.Orientation = Vector3.new(0,0,90)
CapeHeadAttachment.Position = Vector3.new(0,0,0.7)
Beam.Attachment0 = CapeHeadAttachment
Beam.Attachment1 = CapeBottomAttachment
Beam.Texture = "http://www.roblox.com/asset/?id="..texture
Beam.Width0 = 2
Beam.Width1 = 2
Beam.TextureSpeed = 0
Beam.Transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0,0),
NumberSequenceKeypoint.new(1,0)
}
AllignOrientation.Attachment0 = CapeBottomAttachment
AllignOrientation.Attachment1 = CapeTopAttachment1
AllignOrientation.Responsiveness = 20
AllignPosition.Attachment0 = CapeBottomAttachment
AllignPosition.Attachment1 = CapeTopAttachment1
AllignPosition.Position = CapeTopAttachment1.WorldPosition
AllignPosition.Responsiveness = 15
RigidConstraint.Attachment0 = CapeHeadAttachment
RigidConstraint.Attachment1 = CapeTopAttachment2
local finished = false
local function finish(...)
print("finished",...)
finished = true
end
task.spawn(function()
ContentProvider:PreloadAsync({Beam},finish)
end)
while wait(1) do
if not finished then
print("Not Finished")
end
end
CapeTop.Anchored = false
CapeBottom.Anchored = false
CapeBottom.CanCollide = false
CapeBottom.CFrame = Character.HumanoidRootPart.CFrame
CapeTop.CanCollide = false
CapeBottom.Parent = plr.Character
CapeTop.Parent = plr.Character
CapeBottom.Transparency = 1
CapeTop.Transparency = 1
self.CurrentCape = Beam
return setmetatable({},CapeSystem)
end