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

Status Negating script breaks after humanoid death can't figure out why?

Asked by 5 years ago
Edited 5 years ago

Local Script located in StarterPlayerScripts. Throws the error "Nutrition is not a valid member of Frame" which occurs at line 47. Here is the hierarchy of the gui http://gyazo.com/38c20af365389ff1a06c31a08f2328cb

--Establish variables
---------------------------------------------------
local player = game.Players.LocalPlayer
local playerGUI = player.PlayerGui:WaitForChild("PlayerStatus")
local mainFrame = playerGUI:WaitForChild("Frame")
local nutrition = mainFrame.Nutrition.Size.X.Offset
local hydration = mainFrame.Hydration.Size.X.Offset
local nurture = mainFrame.Nurture.Size.X.Offset
local originalNurture = nurture
local originalHydration = hydration
local originalNutrition = nutrition
local debounce = false
local debounceN = false
local debounceH = false
local debounceHealthLoss = true
local lnValue = 2
local lhValue = 3
local statusNegateWait = 1/100
local lhealthValue = 3
--Functions
---------------------------------------------------
function lowerHealth(v)
    if nurture < v then
        mainFrame.Nurture.Size = mainFrame.Nurture.Size-UDim2.new(0,nurture,0,0)
        nurture = 0
        mainFrame.Nurture.TextBox.Text = "Nurture: "..(math.floor(nurture/originalNurture*100)).."%"
        wait(statusNegateWait)
        player.Character.Humanoid.Health = 0
    else
        nurture = nurture-v
        mainFrame.Nurture.Size = mainFrame.Nurture.Size-UDim2.new(0,v,0,0)
        mainFrame.Nurture.TextBox.Text = "Nurture: "..(math.floor(nurture/originalNurture*100)).."%"
    end
end
function lowerNutrition(v)
    if nutrition <= v then
        debounceN = true
        if debounceHealthLoss == true then
            statusNegateWait = 1/10
            debounceHealthLoss = false
        end
        mainFrame.Nutrition.Size = mainFrame.Nutrition.Size-UDim2.new(0,nutrition,0,0)
        nutrition = 0
        mainFrame.Nutrition.TextBox.Text = "Nutrition: "..(math.floor(nutrition/originalNutrition*100)).."%"
    else
        nutrition = nutrition-v
        mainFrame.Nutrition.Size = mainFrame.Nutrition.Size-UDim2.new(0,lnValue,0,0)
        mainFrame.Nutrition.TextBox.Text = "Nutrition: "..(math.floor(nutrition/originalNutrition*100)).."%"
    end
end
function lowerHydration(v)
    if hydration <= v then
        debounceH = true
        if debounceHealthLoss == true then
            statusNegateWait = 1/10
            debounceHealthLoss = false
        end
        mainFrame.Hydration.Size = UDim2.new(0,0,0,20)
        hydration = 0
        mainFrame.Hydration.TextBox.Text = "Hydration: "..(math.floor(hydration/originalHydration*100)).."%"
    else
        hydration = hydration-v
        mainFrame.Hydration.Size = mainFrame.Hydration.Size-UDim2.new(0,lhValue,0,0)
        mainFrame.Hydration.TextBox.Text = "Hydration: "..(math.floor(hydration/originalHydration*100)).."%"
    end
end
while debounce == false do
    if debounceN == false then
        lowerNutrition(lnValue)
    end
    if debounceH == false then
        lowerHydration(lhValue)
    end
    if debounceHealthLoss == true then
        if hydration < 50 or nutrition < 50 then
            lowerHealth(lhealthValue)
        end
    else
        lowerHealth(20)
    end
    wait(statusNegateWait)
end
0
Try using the method :WaitForChild() on that line saSlol2436 716 — 5y
0
I'm declaring what the size of the frame is on that line i can't waitforchild frostysubatomiczero 51 — 5y

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
5 years ago

Use a WaitForChild() at the beginning of the script to yield until the object fully replicates. If you continue to have problems, put in a bunch of print statements to print all the variables and make sure they are each the correct thing. Find the thing that printed the wrong thing and figure out what the problem is from that. You need to reverse engineer your own code sometimes.

Ad

Answer this question