所以我有一个脚本,当单击一个对象时,应该使排行榜上的数字上升,但是1,它不起作用。 2、我希望它是一个普通的点击事件,而不是点击某个对象。
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)
对象中的代码:
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.GoldClick:FireServer()
end)
我试图让排行榜上升,leaderstat 名称为“Gold”,没有错误,但当我单击该部分时,它没有上升。
这有很多问题, 首先,您多次监听同一个 RemoteEvent,这会导致问题,因为您只能处理 RemoteEvent 一次。
您应该将此事件移到设置功能之外,并具有更新任何输入玩家统计数据的功能。
其次,假设Part内的脚本是LocalScript,那么在工作空间下默认是不会运行的。您可以改为使用服务器端脚本来侦听事件(可以与设置leaderstats的脚本相同,将LocalScript移动到它将执行的位置(例如StarterPlayerScripts)或将LocalScript的RunContext设置为“Client”。 请参阅(https://devforum.roblox.com/t/live-script-runcontext/1938784)