lua – 我的代码没有显示错误,但不起作用

huangapple go评论55阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 05:16:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定