Description of my problem:
I have a local script in “PlayerStarterScripts”, in this script I have a function, e.g: change text of a TextLabel.
Now, when the player dies, it will ofc receive new GUI, and local scripts, however, I get errors, from the previous local script, which keeps on stacking.
The script is parented to nil, because i tried to print script.Parent.Name > Output: nil
Now the problem is, I don’t know how to fix it, and more importantly, I don’t know if this bug is causes by Warp, a networking library. THis is because the Function which handles the text change, is initiallized with help of Warp.
My Local Script:
Local Script
ReplicatePlayerDataRE:Connect(function(PlayerData:table)
if PlayerData["Faction"]["Name"] then
local FactionData = GetFactionDataRF:Invoke(10, PlayerData["Faction"]["Name"])
if FactionData then
UpdateGUIElements(FactionData)
elseif localFacionData["Name"] then -- Failsave
UpdateGUIElements(localFacionData)
end
else
if script.Parent then
CanvasTop.Banner.FactionName.Text = "Faction: None"
end
end
end)
The function for changing text
local function UpdateGUIElements(Data:table)
local CoOwnerID
for id, role in pairs(Data.Members) do
if role == "CoOwner" then
CoOwnerID = id
break
end
end
-- CanvasTop
FactionGUIElements.FactionName.Text ="["..Data.Tag.."] "..Data.Name
FactionGUIElements.Description.Text =Data.Desc
FactionGUIElements.Icon.Image ="rbxthumb://type=Asset&id="..Data.Icon.."&w=420&h=420"
FactionGUIElements.Banner.Image ="rbxthumb://type=Asset&id="..Data.Banner.."&w=420&h=420"
-- CanvasMiddle
task.wait(1)
for _,v in ipairs(FactionGUIElements.Information.FactionName:GetChildren()) do
print(v.Name)
end
--Works
FactionUI =PlayerGui.FactionUI
FactionUI.CanvasGroup.Middle.Information.FactionName.TextLabel.Text ="Faction: "..Data.Name
--Error
--FactionUI.CanvasGroup.Middle.Information.FactionName.TextLabel.Text ="Faction: "..Data.Name
--Error
--game.Players.LocalPlayer.PlayerGui.FactionUI.CanvasGroup.Middle.Information.FactionName.TextLabel.Text ="Faction: "..Data.Name
--FactionGUIElements.Information.FactionName.TextLabel.Text ="Faction: "..Data.Name
FactionGUIElements.Information.Tag.TextLabel.Text ="Tag: ["..Data.Tag.."]"
FactionGUIElements.Information.Description.TextLabel.Text ="Description: "..Data.Desc
FactionGUIElements.Information.Owner.TextLabel.Text ="Owner: "..GetUsernameByIDRF:Invoke(10, Data.Owner)
FactionGUIElements.Information.CoOwner.TextLabel.Text ="Co-Owner: "..(GetUsernameByIDRF:Invoke(10, CoOwnerID) or "None")
FactionGUIElements.Information.MemberCount.TextLabel.Text ="MemberCount: "..MainModule.dictionaryCount(Data.Members).." / "..Data.Restrictions.MaxMembers
FactionGUIElements.Information.UniqueID.TextLabel.Text ="UniqueID: "..Data.Restrictions.UniqueID
end