Leaderstats 不工作?或者只是没有检测到点击?
Leaderstats not working? or just not detecting the click?
我正在尝试在 Roblox 上制作模拟器游戏,但我似乎无法让领导者统计数据正常工作,或者它确实有效,但我的点击事件不起作用,我只是按照教程进行操作脚本所以我不知道。这是我的 Remotes 脚本,其中显示 print("IS THIS WORKING") 是为了查看问题所在。基本上这不会 运行 或者还有另一个问题阻止了 运行ning,我认为至少。我还有其他脚本,我会放一些我认为可能需要的脚本,但如果您需要更多,请随时问我。
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)
对于我的资源管理器结构,请单击
here
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
你的问题是当它等待 child 它产生脚本直到找到 RemoteData
稍后在脚本中,它会检查 RemoteData 是否为 nil
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
两种解决方案:
首先是添加最大等待产量,这样如果找不到 RemoteData 它最终会停止(只有在脚本启动后添加 RemoteData 才有用 运行)
第二个是用 FindFirstChild 替换等待,它将立即检查而不等待它
我推荐的方案
local remoteData = game:GetService("ServerStorage"):FindFirstChild("RemoteData")
第二个解决方案,如果你在脚本启动后添加了 RemoteData 并且想要 double-check
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData",20)
请务必告诉我这是否有效,因为我花了一段时间才弄明白
我正在尝试在 Roblox 上制作模拟器游戏,但我似乎无法让领导者统计数据正常工作,或者它确实有效,但我的点击事件不起作用,我只是按照教程进行操作脚本所以我不知道。这是我的 Remotes 脚本,其中显示 print("IS THIS WORKING") 是为了查看问题所在。基本上这不会 运行 或者还有另一个问题阻止了 运行ning,我认为至少。我还有其他脚本,我会放一些我认为可能需要的脚本,但如果您需要更多,请随时问我。
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)
对于我的资源管理器结构,请单击 here
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
你的问题是当它等待 child 它产生脚本直到找到 RemoteData
稍后在脚本中,它会检查 RemoteData 是否为 nil
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
两种解决方案: 首先是添加最大等待产量,这样如果找不到 RemoteData 它最终会停止(只有在脚本启动后添加 RemoteData 才有用 运行)
第二个是用 FindFirstChild 替换等待,它将立即检查而不等待它
我推荐的方案
local remoteData = game:GetService("ServerStorage"):FindFirstChild("RemoteData")
第二个解决方案,如果你在脚本启动后添加了 RemoteData 并且想要 double-check
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData",20)
请务必告诉我这是否有效,因为我花了一段时间才弄明白