【问题标题】:My script is not able to change the value for some reason(roblox)我的脚本由于某种原因无法更改值(roblox)
【发布时间】:2022-03-22 04:23:29
【问题描述】:

所以我做了一个按钮,当按下它时,给按下它的玩家一个盔甲。要检查玩家是否已经拥有盔甲,我使用 Instance.new 创建一个布尔值并检查按钮脚本中的值。但是由于某种原因,即使我输入了正确的路径,该值也根本没有改变。

这里是按钮脚本:

function giveArmor(Clicker)
    local newArmor = game.ServerStorage["Light vest VOG-1"]:Clone()
    local charatcer = Clicker.Character
    local humanoid = charatcer.Humanoid
    local isArmorOn = humanoid.ArmorFolder:WaitForChild("IsArmorOn").Value
    print(isArmorOn)
    if isArmorOn == false then
        newArmor.Parent = charatcer
        newArmor.Name = "InGameArmor"
        isArmorOn = true
        humanoid.ArmorFolder:WaitForChild("PhysicalDamageResist").Value = 0.85
        humanoid.ArmorFolder:WaitForChild("ArmorName").Value = "Light vest VOG-1"
    end
end

script.Parent.MouseClick:Connect(giveArmor)

这是创建新值的脚本:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Character)
        local humanoid = Character:FindFirstChild("Humanoid")
        --//Stuff in armor folder//------------------------------
        local armorFolder = Instance.new("Folder", humanoid)
        armorFolder.Name = "ArmorFolder"
        local pResist = Instance.new("NumberValue", armorFolder)
        pResist.Name = "PhysicalDamageResist"
        pResist.Value = 1
        local mResist = Instance.new("NumberValue", armorFolder)
        mResist.Name = "MentalDamageResist"
        mResist.Value = 1
        local cResist = Instance.new("NumberValue", armorFolder)
        cResist.Name = "CompoundDamageResist"
        cResist.Value = 1.5
        local tResist = Instance.new("NumberValue", armorFolder)
        tResist.Name = "TruePhysicalDamageResist"
        tResist.Value = 2
        local armorName = Instance.new("StringValue", armorFolder)
        armorName.Name = "ArmorName"
        armorName.Value = "None"
        local armorCheck = Instance.new("BoolValue", armorFolder)
        armorCheck.Name = "IsArmorOn"
        armorCheck.Value = false
        --//SP//-----------------------------------------------
        local maxSP = Instance.new("NumberValue", humanoid)
        maxSP.Name = "MaxSP"
        maxSP.Value = 100
        local sp = Instance.new("NumberValue", humanoid)
        sp.Name = "SP"
        sp.Value = 100
        --//Other stuff//-------------------------------------
        humanoid.NameDisplayDistance = 0 -- Disable name display
        Character.Health.Disabled = true -- Disable regen
    end)
end)

【问题讨论】:

标签: roblox


【解决方案1】:

当您定义 isArmorOn 变量时,您会立即将其设置为 bool 所处的状态。这意味着该变量仅包含 True 或 False,但不包含它从何处获得该值。相反,您应该做的是:

local isArmorOn = humanoid.ArmorFolder:WaitForChild("IsArmorOn").Value
--and for changing the variable
isArmorOn.Value = true

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多