Function doesnt change a variable

image
so i have this simple script but for some reason it doesnt change the variable.
i dont really know why could this be happening

You need to return the variable like this

local function getLowestBranch(branch, variable)
if then

return variable
else

return variable
end
end

Then you would need to set the variable using this

MyVariable = getLowestBranch(branch, variable)

Also you can’t call the function that you’re defining

You’re setting “lowerbranch” to a number value, while you’ve to get the object value and tell it which property to change.
Properties can’t be object values.

local function getLowestBranch(branch,variable)
    if branch:FindFirstChild("Rodzic") then
        local lowerBranch = branch.Rodzick
        getLowestBranch(lowerbranch,variable)
    else
        variable = branch
    end
end

Note that, variable and branch have to be both object values as well.
And instead of that I suggest using return;

local function getLowestBranch(branch)
    if branch:FindFirstChild("Rodzic") then
        local lowerBranch = branch.Rodzick
        return getLowestBranch(lowerbranch,variable)
    else
        return branch
    end
end

variable = getLowestbranch(branch) -- whatever "variable" is