【发布时间】:2021-06-19 21:14:52
【问题描述】:
所以我正在制作一个每分钟给你 5 现金的脚本,我还为该脚本制作了一个游戏通行证,如果有人拥有游戏通行证,他们将作为非游戏通行证持有者获得双倍的钱。这是我的脚本 我没有任何脚本可以提供现金,但问题出在第二个脚本块中,控制台打印错误:
09:10:57.466 ServerScriptService.CashGiver:6: attempt to index nil with 'UserId' - Server - CashGiver:6
local Give5Cash = game.ReplicatedStorage:WaitForChild("Give5Cash")
local Give10Cash = game.ReplicatedStorage:WaitForChild("Give10Cash")
Give5Cash.OnServerEvent:Connect(function()
print("Player Will Be Given 5 Cash")
end)
Give10Cash.OnServerEvent:Connect(function()
print("Player Will Be Given 10 Cash")
end)
while wait() do
local MPS = game:GetService("MarketplaceService")
local id = 16031172
local player = game.Players.LocalPlayer
if MPS:UserOwnsGamePassAsync(player.UserId, id) then
game.ReplicatedStorage:WaitForChild("Give10Cash"):FireServer()
print("Player Owns 2x Cash")
else
print("Players Doesnt Owns 2x Cash")
game.ReplicatedStorage:WaitForChild("Give5Cash"):FireServer()
end
wait(5)
end
【问题讨论】: