Just before I start, I’m really new to Roact but I value the features that it supports so I’m trying to implement it.
I wanted to use a component within a component (as a function) so I can automatically add a shadow effect behind my TextLabels. Here is my code for that (it’s autocompiled from roblox-ts so excuse the weird indenting and semicolons)
local function TextLabelWithBacking(Props)
local subProps = Props;
subProps.Position = UDim2.new(0, 0, 0, 2);
subProps.Size = UDim2.new(1, 0, 1, 0);
subProps.TextColor3 = Props.TextColor3:Lerp(Color3.new(0, 0, 0), .75);
return Roact.createElement("TextLabel", Props, {
Back = Roact.createElement("TextLabel", subProps);
});
end;
local function Detain(props)
local username = props.username;
return Roact.createElement("ScreenGui", {
ZIndexBehavior = Enum.ZIndexBehavior.Global,
ResetOnSpawn = false
} , {
["Detain"] = Roact.createElement(TextLabelWithBacking, {
Size = UDim2.new(1, 0, 0, 50),
BackgroundTransparency = 1,
Font = Enum.Font.GothamBold,
TextScaled = true,
Position = UDim2.new(0, 0, .5, 0),
AnchorPoint = Vector2.new(0, 0.5),
TextColor3 = Color3.new(1, 1, 1),
ZIndex = 2,
Text = "You are being detained by " .. username .. "."
} , {
["SubHeader"] = Roact.createElement(TextLabelWithBacking, {
Size = UDim2.new(.5, 0, 0, 30),
Position = UDim2.new(0.5, 0, 1, 0),
TextScaled = true,
ZIndex = 2,
AnchorPoint = Vector2.new(.5, 0),
BackgroundTransparency = 1,
Font = Enum.Font.GothamBold,
TextColor3 = Color3.new(1, 1, 1),
Text = "Your weapons are now useless."
} , {
})
})
});
end;
For some reason that I’m unable to traceback since this crashes my studio in test mode and produces this unhelpful stack trace:
Can anyone with experience with Roact let me know where I’m going wrong? I’m unable to find anything different in the docs to what I’m doing.