Leaderstats无法正常工作?还是没有检测到点击?

我正在尝试制作Roblox上的模拟器游戏,但我似乎无法使领袖统计数据工作,或者它确实工作,而我的点击事件无法正常工作,我只是遵循脚本教程,所以我一无所知。这是我的Remotes脚本,其中打印的内容是"IS THIS WORKING",这是为了查看问题所在。基本上,那个不运行,或者有另一个问题阻止它运行,至少我这么认为。我有其他的脚本,我会放一些我认为可能是必要的,但是如果您需要更多,请随时问我。

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")

local cooldown = 1
print("IS THIS WORKING")

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)


    if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end


    local debounce = remoteData[player.Name].Debounce

    if not debounce then

        debounce.Value = true

        player.leaderstats.Stealth.Value = player.leaderstats.Stealth.Value + 25 *(player.leaderstats.Rebirths.Value + 1)
        wait(cooldown)

        debounce.Value = false

    end

统计数据

local serverStorage = game:GetService("ServerStorage")

game.Players.PlayerAdded:Connect(function(player)


    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local stealth = Instance.new("NumberValue")
    stealth.Name = "Stealth"
    stealth.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Parent = leaderstats

    local Folder = Instance.new("Folder")
    Folder.Name = player.Name
    Folder.Parent = serverStorage.RemoteData

    local debounce = Instance.new("BoolValue")
    debounce.Name = "Debounce"
    debounce.Parent = Folder


    end)

模块脚本

local module = {}

local replicatedStorage = game:GetService("ReplicatedStorage")
function module.Lift()

    replicatedStorage.Remotes.Lift:FireServer()

end
return module

本地脚本

local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
    module.Lift()
end)

对于我的Explorer结构,请单击 这里

点赞
用户88888888
用户88888888
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")

你的问题是等待一个子对象时它会暂停脚本直至找到 RemoteData,

接着,在脚本中,它将检查 RemoteData 是否为空。

if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

有两个解决方法: 第一个解决方法是添加最大等待时间以防找不到 RemoteData 而脚本始终暂停(仅在脚本开始运行后添加 RemoteData 时有用)。

第二个解决方法是用 FindFirstChild 替换 WaitForChild,它将立即检查而不需要等待。

我推荐的解决方法是

local remoteData = game:GetService("ServerStorage"):FindFirstChild("RemoteData")

备选的解决方法是,如果你在脚本开始后添加了 RemoteData ,想要进行二次检查

local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData",20)

请确定是否有效,因为我花了一段时间才想出这个解决方案。

2020-06-21 04:43:00