我的目标是创建一个变量(_G.rownedB和_G.gownedB),每1秒向_G.RPoints或_G.GPoints 1添加一个点,直到其中任何一个有1200点为止。不幸的是,它似乎没有正常运行,而是根本无法工作,启动游戏并看到当我捕捉到点时,点gui文本(_G.News.Text)不起作用。我的错是什么?
-- Script by Dropdatderp
capturing = nil
_G.rownedB = false
_G.gownedB = false
neutral = true
function get_player(part)
for _, player in ipairs(game.Players:GetPlayers()) do
if part:IsDescendantOf(player.Character) then
return player
end
end
end
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
if _G.gownedB or neutral == true then
capturing = true
_G.News.Text = "Raiders are taking Point B!"
wait(10)
_G.News.Text = "Raiders have taken Point B."
capturing = nil
_G.rownedB = true
_G.gownedB = false
neutral = false
end
elseif _G.rownedB or neutral == true then
local player = get_player(part)
if player:IsInGroup("901313") then
capturing = true
_G.News.Text = "Defenders are taking Point B!"
wait(10)
_G.News.Text = "Defenders have taken Point B."
capturing = nil
_G.rownedB = false
_G.gownedB = true
neutral = false
repeat
wait(1)
_G.RPoints = _G.RPoints + 1
until _G.RPoints or _G.GPoints == 1200
end
end
end
repeat
script.Parent.Touched:connect(get_player)
script.Parent.Touched:connect(onTouched)
until _G.GPoints == 1200 or _G.RPoints == 1200
答案 0 :(得分:0)
首先,请检查您的if语句。 这就像你想要的那样吗?
if h ~= nil then
if _G.gownedB or neutral == true then
end
elseif _G.rownedB or neutral == true then
if player:IsInGroup("901313") then
end
end
或者更确切地说
if h ~= nil then
if _G.gownedB or neutral == true then
elseif _G.rownedB or neutral == true then
if player:IsInGroup("901313") then
end
end
end
...
另外,请确保您了解此行的作用:
script.Parent.Touched:connect(onTouched)
并且问自己,多次调用它是有意义的。 你会不会留下那个重复,直到陈述?
你在这里遗失了什么吗?
repeat
wait(1)
_G.RPoints = _G.RPoints + 1
until _G.RPoints or _G.GPoints == 1200
这会有用吗?
仔细阅读您的代码,问问自己您想做什么以及发生了什么。绘制一个简单的流程图或决策树,并播放几个案例......