英文:
lua - my code displays no errors but doesn't work
问题
在代码的下半部分,我试图使得当在上一个硬币生成后的10秒内被收集时,通过 +30 增加“coins”分数。我已尝试重新排列代码,但只会导致错误。该代码仅在默认情况下工作区中的第一个硬币上运行。请问有谁知道问题并能帮助我吗?
英文:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local CoinsCollected = Instance.new("IntValue", leaderstats)
CoinsCollected.Name = "Coins"
end)
local AppleCoinRedClone = game.Workspace.AppleCoinRedClone
local Debounce = false
local Players = game:GetService("Players")
wait(1)
AppleCoinRedClone.Touched:Connect(function(PartB)
local player = Players:GetPlayerFromCharacter(PartB.Parent)
if not player then return end
local leaderstats = player.leaderstats
local CoinsCollected = leaderstats.Coins
if PartB.Parent:FindFirstChild("Humanoid") then
if not Debounce then
Debounce = true
CoinsCollected.Value = CoinsCollected.Value + 30
wait(3)
Debounce = false
end
end
end)
It works on the first coin that is inside the game by default but not on the coins after. There is only 1 coin in workspace at once.
i'm trying to, in the bottom half of the code to make it so that when the coin that spawns in 10 seconds after the previous has been collected, to add to the "coins" score by +30. I have tried re - ordering the code but it only gives me errors. the code only works on the first coin that is already in the workspace by default. Please, does anyone know the problem and can help me out?
答案1
得分: -2
Your code doesn't work because of the end)
block at line six. It blocks the other lines of code, as it only should be used at the end.
Source:
https://www.lua.org/pil/4.4.html
英文:
Your code doesn't work because of the end)
block at line six. It blocks the other lines of code, as it only should be used at the end.
Source:
https://www.lua.org/pil/4.4.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论