在 roblox studio 中按下一个按钮和文本增加 +1
Press a button and text increase +1 in roblox studio
有人可以帮我解决这个错误吗?
我创建了一个名为“TextButton”的按钮,我有一个名为“TextLabel”的文本,我需要做的是在我按下“TextButton”按钮时使“TextLabel”增加 1,请有人帮我解决这个问题。
function script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel = "clicks: "..script.Parent.ValorVoto.Value
end
script.Parent.Parent.TextButton.MouseButton1Down:Connect(clicking)
我认为你遇到了语法错误。看起来您正在定义一个函数,但还试图将该函数立即连接到 TextButton。尝试将您的函数命名为 clicking
,然后将其传递给连接。
function clicking()
print("working..?..")
local vv = script.Parent.ValorVoto
vv.Value = vv.Value + 1
script.Parent.Parent.TextLabel.Text = "clicks: " .. tostring(vv.Value)
end
script.Parent.MouseButton1Click:Connect(clicking)
您在此脚本中有 2 个错误:
- 第 4 行,在引用 TextLabel 后添加一个
.Text
。
- 正如 Kylaa 所说,第 7 行有一个错误,您可以删除该行,因为您的函数已通过事件调用。您不需要重新调用该函数,而且您尝试调用的函数不存在。
- 如果它已经在侦听事件,则不要将其标记为函数。
script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel.Text = "clicks: "..script.Parent.ValorVoto.Value
end
有人可以帮我解决这个错误吗?
我创建了一个名为“TextButton”的按钮,我有一个名为“TextLabel”的文本,我需要做的是在我按下“TextButton”按钮时使“TextLabel”增加 1,请有人帮我解决这个问题。
function script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel = "clicks: "..script.Parent.ValorVoto.Value
end
script.Parent.Parent.TextButton.MouseButton1Down:Connect(clicking)
我认为你遇到了语法错误。看起来您正在定义一个函数,但还试图将该函数立即连接到 TextButton。尝试将您的函数命名为 clicking
,然后将其传递给连接。
function clicking()
print("working..?..")
local vv = script.Parent.ValorVoto
vv.Value = vv.Value + 1
script.Parent.Parent.TextLabel.Text = "clicks: " .. tostring(vv.Value)
end
script.Parent.MouseButton1Click:Connect(clicking)
您在此脚本中有 2 个错误:
- 第 4 行,在引用 TextLabel 后添加一个
.Text
。 - 正如 Kylaa 所说,第 7 行有一个错误,您可以删除该行,因为您的函数已通过事件调用。您不需要重新调用该函数,而且您尝试调用的函数不存在。
- 如果它已经在侦听事件,则不要将其标记为函数。
script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel.Text = "clicks: "..script.Parent.ValorVoto.Value
end