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

How to disable/enable beam by Conditional Structures?

Asked by
TechModel 118
3 years ago

Trying to get this Local Script located in StarterPlayerScript to enable the beam when the player stats have >= 1, meaning 1 or greater than that value. If it equals 0 or less, then the beam gets destroyed. Not sure to destroy it or hide it.

local plr = game.Players.LocalPlayer

plr:WaitForChild("stats").Liquid:GetPropertyChangedSignal("Value"):Connect(function(plr)

    local plr = game.Players.LocalPlayer
    local beam = script:WaitForChild("Beam"):Clone()

    local function pathToPart(beam, a0, part) --Function to make making paths easier
        local a1 = part:FindFirstChildOfClass("Attachment")--Find the attachment in the part
        if a1 then
            beam.Attachment0 = a0
            beam.Attachment1 = a1
        else
            warn("No attachment was inserted into "..part:GetFullName())
        end
    end

        if plr.stats.Liquid.Value >= 1 then
    local root = plr:WaitForChild("HumanoidRootPart")
    local a0 = root:WaitForChild("RootRigAttachment")
    pathToPart(beam, a0, workspace:WaitForChild("Part"))
        beam.Parent = plr

    elseif plr.Stats.Liquid.Value <= 0 then
        beam:Destroy()
    end
end)

Answer this question