由于某种原因,我的脚本无法更改值(roblox)



所以我做了一个按钮,当按下它时,给按下它的玩家一个盔甲。为了检查玩家是否已经有盔甲,我使用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)

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

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

最新更新