Hello everyone, I have a problem that after the Proximity Prompts trigger the function does not find the Humanoid and the script does not work.
local ItemPricesScript = require(game.ReplicatedStorage:WaitForChild("BuyingItems"):WaitForChild("ItemPrices"))
local Promt = script.Parent.Parent.AmongusPLUSHIE.Buy
Promt.Triggered:Connect(function(Triggered)
local ItemName = script.Parent.Name
repeat wait() until Triggered:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(Triggered)
if plr then
local OwnedItems = plr.OwnedItems
if OwnedItems:FindFirstChild(script.Parent.Parent.Parent.Name) then return end
plr.PlayerGui.BuyQ.MainFrame.Visible = true
plr.PlayerGui.BuyQ.MainFrame.Desription.Text = "Would you like to purchase the " ..ItemName.. " ???"
plr.PlayerGui.BuyQ.MainFrame.Desription.Yes.LocalScript.ItemName.Value = ItemName
end
wait(1)
end)
I used to make the same script but without Proximity Prompts.
local ItemPricesScript = require(game.ReplicatedStorage:WaitForChild("BuyingItems"):WaitForChild("ItemPrices"))
local Promt = script.Parent.Parent.AmongusPLUSHIE.Buy
Promt.Triggered:Connect(function(Triggered)
local ItemName = script.Parent.Name
repeat wait() until Triggered:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(Triggered)
if plr then
local OwnedItems = plr.OwnedItems
if OwnedItems:FindFirstChild(script.Parent.Parent.Parent.Name) then return end
plr.PlayerGui.BuyQ.MainFrame.Visible = true
plr.PlayerGui.BuyQ.MainFrame.Desription.Text = "Would you like to purchase the " ..ItemName.. " ???"
plr.PlayerGui.BuyQ.MainFrame.Desription.Yes.LocalScript.ItemName.Value = ItemName
end
wait(1)
end)
When I triggered Proximity Prompts there was no action, and when I left the place I got this error
error - " Workspace.Podval.Shop.Amogus.AmongusPLUSHIE.Script:6: attempt to index nil with ‘FindFirstChild’ "
[image]
Use this, will work, I remembered how they actually work now.
local ItemPricesScript = require(game.ReplicatedStorage:WaitForChild("BuyingItems"):WaitForChild("ItemPrices"))
local Promt = script.Parent.Parent.AmongusPLUSHIE.Buy
Promt.Triggered:Connect(function(plr) --returns the player object not the character.
local ItemName = script.Parent.Name
local OwnedItems = plr.OwnedItems
if OwnedItems:FindFirstChild(script.Parent.Parent.Parent.Name) then return end
plr.PlayerGui.BuyQ.MainFrame.Visible = true
plr.PlayerGui.BuyQ.MainFrame.Desription.Text = "Would you like to purchase the " ..ItemName.. " ???"
plr.PlayerGui.BuyQ.MainFrame.Desription.Yes.LocalScript.ItemName.Value = ItemName
wait(1)
end)