Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix the Overhead it suddenly stop working?

Asked by 1 year ago

I edited an overhead cloning script and it works for a long time now but it suddenly stop working, what I try first was to Remove the script base on an error but it doesn' t work, so next I try to Donwdate the game using the version which work perfectly but it doesnt solve the problem.

The error message have something to do on the "Role" which I tried to delete but it doesn't work, I think it is cause by some update made by roblox.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Overheads = ReplicatedStorage:WaitForChild("OverheadsGui")
local GroupId = 11540689    ----// GROUP ID

            local Left = Overheads:WaitForChild("Left")
            local Right = Overheads:WaitForChild("Right")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        -- These variables are used regardless of whether the user owns the gamepass or not
        -- so we can define them outside the if statement
        local Humanoid = Character:WaitForChild("Humanoid")
        local Head = Character:WaitForChild("Head")

        local Stats = Player:WaitForChild("playerstats").Rank.Value

        -- Again, this happens regardless of the if statement
        Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
        if Stats == "Unrank" then
            Left.Image = "rbxassetid://11260847774"
            Right.Image = "rbxassetid://11260873360"

        elseif Stats == "Bronze" then
            Left.Image = "rbxassetid://11260880194"
            Right.Image = "rbxassetid://11260884454"

        elseif Stats == "Silver" then
            Left.Image = "rbxassetid://11260890595"
            Right.Image = "rbxassetid://11260895668"

        elseif Stats == "Gold" then
            Left.Image = "rbxassetid://11260902279"
            Right.Image = "rbxassetid://11260906114"

        elseif Stats == "GoldPlus" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Creator" then
        Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Tester" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Contributor" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"
        end

        local CloneGui = Overheads:Clone()
        CloneGui.Username.Text = Player.Name
        CloneGui.Parent = Head
        CloneGui.Name = "OverheadGui"
        local Role = "Guest"
        pcall(function()
            Role = Player:GetRoleInGroup(GroupId)
        end)
        CloneGui.Role.Text = Role
    end)
end)

1 answer

Log in to vote
0
Answered by 1 year ago

There were a few issues in your code,

In the original code, the Left and Right variables were being defined outside the Player.CharacterAdded event handler, which means that they would be defined regardless of whether the player's character has been added or not. Since these variables are used later on in the code, this could cause errors if the player's character has not been added yet.

By moving the declarations of Left and Right inside the Player.CharacterAdded event handler, we ensure that these variables are only defined when the player's character is added, which eliminates the potential for errors.

Here is a fixed version of your code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Overheads = ReplicatedStorage:WaitForChild("OverheadsGui")
local GroupId = 11540689    ----// GROUP ID

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        -- These variables are used regardless of whether the user owns the gamepass or not
        -- so we can define them outside the if statement
        local Humanoid = Character:WaitForChild("Humanoid")
        local Head = Character:WaitForChild("Head")
        local Left = Overheads:WaitForChild("Left")
        local Right = Overheads:WaitForChild("Right")

        local Stats = Player:WaitForChild("playerstats").Rank.Value

        -- Again, this happens regardless of the if statement
        Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
        if Stats == "Unrank" then
            Left.Image = "rbxassetid://11260847774"
            Right.Image = "rbxassetid://11260873360"

        elseif Stats == "Bronze" then
            Left.Image = "rbxassetid://11260880194"
            Right.Image = "rbxassetid://11260884454"

        elseif Stats == "Silver" then
            Left.Image = "rbxassetid://11260890595"
            Right.Image = "rbxassetid://11260895668"

        elseif Stats == "Gold" then
            Left.Image = "rbxassetid://11260902279"
            Right.Image = "rbxassetid://11260906114"

        elseif Stats == "GoldPlus" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Creator" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Tester" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"

        elseif Stats == "Contributor" then
            Left.Image = "rbxassetid://11260911548"
            Right.Image = "rbxassetid://11260917532"
        end

        local CloneGui = Overheads:Clone()
        CloneGui.Username.Text = Player.Name
        CloneGui.Parent = Head
        CloneGui.Name = "OverheadGui"
        local Role = "Guest"
        pcall(function()
            Role = Player:GetRoleInGroup(GroupId)
        end)
        CloneGui.Role.Text = Role
    end)
end)

0
Still not work, I received this error message "Role is not a valid member of BillboardGui "OverheadGui" However the Role exist on the OverheadGui. AltairCelestia 47 — 1y
0
Are you doing OverheadGui[Role].Value ? NovaGooBoom 42 — 1y
0
I'm not sure about what do you mean but, Do have a textframe which named as Role and it is a member of OverheadGui AltairCelestia 47 — 1y
1
Thank you for your help, I make a new script using starterplayer instead for player and character added and it works AltairCelestia 47 — 1y
Ad

Answer this question