每次单击此按钮时如何将 1 添加到排行榜?
How to add 1 to the leaderboard everytime this button is clicked?
我正在尝试制作一个脚本,当您单击此按钮时,排行榜会增加 1。这就是我目前得到的结果:
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local function upd()
gold.Value = gold.Value + 1
end
game:GetService("StarterGui").ScreenGui.TextButton.MouseButton1Click:Connect(upd)
end
Players.PlayerAdded:Connect(leaderboardSetup)
非常感谢!
您使用的代码正在获取 StarterGui 对象。该对象被克隆到播放器的 PlayerGui 中。
要正确连接它,请在 ReplicatedStorage 中创建一个 remoteEvent 并将其命名为“GoldClick”
在 ServerScriptService 中使用这样的脚本
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local function upd()
gold.Value = gold.Value + 1
end
game.ReplicatedStorage.GoldClick.OnServerEvent:Connect(function(Localplayer)
if player.Name == Localplayer.Name then
upd()
end
end)
end
Players.PlayerAdded:Connect(leaderboardSetup)
然后,在按钮内创建一个 LocalScript 并使用下面的代码
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.GoldClick:FireServer()
end)
我正在尝试制作一个脚本,当您单击此按钮时,排行榜会增加 1。这就是我目前得到的结果:
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local function upd()
gold.Value = gold.Value + 1
end
game:GetService("StarterGui").ScreenGui.TextButton.MouseButton1Click:Connect(upd)
end
Players.PlayerAdded:Connect(leaderboardSetup)
非常感谢!
您使用的代码正在获取 StarterGui 对象。该对象被克隆到播放器的 PlayerGui 中。
要正确连接它,请在 ReplicatedStorage 中创建一个 remoteEvent 并将其命名为“GoldClick”
在 ServerScriptService 中使用这样的脚本
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local function upd()
gold.Value = gold.Value + 1
end
game.ReplicatedStorage.GoldClick.OnServerEvent:Connect(function(Localplayer)
if player.Name == Localplayer.Name then
upd()
end
end)
end
Players.PlayerAdded:Connect(leaderboardSetup)
然后,在按钮内创建一个 LocalScript 并使用下面的代码
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.GoldClick:FireServer()
end)