当玩家与接近提示交互时,它会检查玩家是否有工具,如果没有,那么它会执行一个功能 -ROBLOX STUDIO
When player interacts with proximity prompt it checks if the player has a tool, if not then it does a function -ROBLOX STUDIO
我正在制作一个当玩家与邻近提示交互时显示的图形用户界面,但是,我希望脚本检查玩家的物品栏中是否有该工具。如果它有工具,那么什么都不做(不要
t 显示 gui),如果它没有该工具,则触发一个事件。我试过了,但这个错误一直出现 Workspace.Part.Script:6: attempt to index nil with 'Backpack'
这是脚本:
debounce = true
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
if debounce then
debounce = false
local noob = game.Players:GetPlayerFromCharacter(player.Parent)
local Tool = noob.Backpack:FindFirstChild("Gunball")
if Tool == nil then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
debounce = true
end
end
end)
这是 gui 脚本(本地),即使我真的不认为它有用..:[=12=]
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = true
end)
Workspace.Part.Script:6:尝试用 'Backpack'
索引 nil
local Tool = noob.Backpack:FindFirstChild("Gunball")
这里noob
是nil
.
所以在local noob = game.Players:GetPlayerFromCharacter(player.Parent)
game.Players:GetPlayerFromCharacter(player.Parent)
returnsnil
.
This function returns the Player associated with the given
Player.Character, or nil if one cannot be found. It is equivalent to
the following function:
local function getPlayerFromCharacter(character)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Character == character then
return player
end
end
end
所以player
、player.Parent
的Parent
似乎不是与任何玩家关联的Character
。
为什么像 Character
这样的 属性 玩家应该成为 parent 玩家?我不是 Roblox 专家,但这对我来说似乎没有任何意义。
如果你想检查触发 ProximitPrompt 的玩家是否有一些物品,为什么不使用 player
?我的意思是那是触发它的玩家。所以检查它的背包,而不是一些 parent 角色的东西。
我正在制作一个当玩家与邻近提示交互时显示的图形用户界面,但是,我希望脚本检查玩家的物品栏中是否有该工具。如果它有工具,那么什么都不做(不要 t 显示 gui),如果它没有该工具,则触发一个事件。我试过了,但这个错误一直出现 Workspace.Part.Script:6: attempt to index nil with 'Backpack' 这是脚本:
debounce = true
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
if debounce then
debounce = false
local noob = game.Players:GetPlayerFromCharacter(player.Parent)
local Tool = noob.Backpack:FindFirstChild("Gunball")
if Tool == nil then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
debounce = true
end
end
end)
这是 gui 脚本(本地),即使我真的不认为它有用..:[=12=]
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = true
end)
Workspace.Part.Script:6:尝试用 'Backpack'
索引 nillocal Tool = noob.Backpack:FindFirstChild("Gunball")
这里noob
是nil
.
所以在local noob = game.Players:GetPlayerFromCharacter(player.Parent)
game.Players:GetPlayerFromCharacter(player.Parent)
returnsnil
.
This function returns the Player associated with the given Player.Character, or nil if one cannot be found. It is equivalent to the following function:
local function getPlayerFromCharacter(character) for _, player in pairs(game:GetService("Players"):GetPlayers()) do if player.Character == character then return player end end end
所以player
、player.Parent
的Parent
似乎不是与任何玩家关联的Character
。
为什么像 Character
这样的 属性 玩家应该成为 parent 玩家?我不是 Roblox 专家,但这对我来说似乎没有任何意义。
如果你想检查触发 ProximitPrompt 的玩家是否有一些物品,为什么不使用 player
?我的意思是那是触发它的玩家。所以检查它的背包,而不是一些 parent 角色的东西。