所以我试图在凌晨 1 点制作一个 Roblox 游戏,因为谁不这样做,我遇到了一个小问题:我有一个变量不会在我的服务器脚本中更新,即使我可以看到它在资源管理器和 Leaderstats 中更新。
我的栽培切换脚本(文本按钮下的本地脚本):
local button = script.Parent
local cultivating = game.Players.LocalPlayer.leaderstats.Cultivating
button.MouseButton1Click:Connect(function()
if cultivating.Value == false then
cultivating.Value = true
button.Text = "Stop Cultivating"
else
cultivating.Value = false
button.Text = "Start Cultivating"
end
end)
我的leaderstats脚本(serverscriptservice下的服务器脚本):
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local qi = Instance.new("IntValue")
qi.Name = "Qi"
qi.Value = 0
qi.Parent = leaderstats
local cultivating = Instance.new("BoolValue")
cultivating.Name = "Cultivating"
cultivating.Value = true
cultivating.Parent = leaderstats
end)
我的培养脚本(serverscriptservice下的服务器脚本):
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local qi = leaderstats:WaitForChild("Qi")
local cultivating = leaderstats:WaitForChild("Cultivating")
while true do
if cultivating.Value == true then
qi.Value += 1
end
wait(0.5)
end
end)
我知道这可能是一个愚蠢的问题,在您运行“否决”按钮之前,请记住现在是凌晨 2:03,我已经要求 chatgpt 和 claude ai 帮助我,但他们都失败了。基本上,变量“栽培”是由本地脚本更新的,该脚本可以工作,但不会在栽培脚本内更新。
我预计如果我在修炼的话,它会每0.5秒给我1气。
我尝试使用人工智能来帮助我(浪费时间),尝试使用一堆打印语句进行调试,并得出结论,它确实是脚本内的变量没有更新。我什至尝试在循环内声明变量但没有成功。