I’m trying to make a system where when the player triggers the proximity prompt, their tool will be destroyed.
Even through there are no errors in output, it doesn’t work. It doesn’t even print anything.
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
--
local ValueFolder = player:WaitForChild("ValueFolder")
local InventoryValue = ValueFolder.InventoryValue
-- PLAYER'S CHARACTER/BACKPACK
if player.Character and player.Backpack then
for i,v in pairs(player.Character:GetChildren() and player.Backpack:GetChildren()) do
if v:IsA("Tool") then
--
v:Destroy()
print("Destroy Item")
InventoryValue.Value = false
--
elseif not v:IsA("Tool") then
--
print("Player does NOT have Item")
ShowYouDontHaveEvent:FireClient(player)
wait(3)
HideYouDontHaveEvent:FireClient(player)
--
end
end
end
end)
If you need more information just ask.
Any help is appreciated!
player.Character:GetChildren() and player.Backpack:GetChildren()
This should error or only iterate through the backpack. In lua and/or will not combine tables, you will either have to iterate over both separately or combine the tables.
Could you try replacing the code with this and show us the output? When a problem like this occurs, I generally add print statements to every if statement to see if it runs or not.
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
print("Triggered")
--
local ValueFolder = player:WaitForChild("ValueFolder")
local InventoryValue = ValueFolder.InventoryValue
-- PLAYER'S CHARACTER/BACKPACK
if player.Character and player.Backpack then
print("Player and Player.Character")
for i,v in pairs(player.Character:GetChildren() and player.Backpack:GetChildren()) do
print(v.Name)
if v:IsA("Tool") then
--
v:Destroy()
print("Destroy Item")
InventoryValue.Value = false
--
elseif not v:IsA("Tool") then
--
print("Player does NOT have Item")
ShowYouDontHaveEvent:FireClient(player)
wait(3)
HideYouDontHaveEvent:FireClient(player)
--
end
end
end
end)
I think I see what you’re saying, but I can’t quite do it.
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
--
local ValueFolder = player:WaitForChild("ValueFolder")
local InventoryValue = ValueFolder.InventoryValue
-- PLAYER'S CHARACTER
if player.Character then
for i,v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
--
v:Destroy()
print("Destroy Item")
InventoryValue.Value = false
--
elseif not v:IsA("Tool") then
--
print("Player does NOT have Item")
ShowYouDontHaveEvent:FireClient(player)
wait(3)
HideYouDontHaveEvent:FireClient(player)
--
end
end
-- PLAYER'S BACKPACK
elseif player.Backpack then
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
--
v:Destroy()
print("Destroy Item")
InventoryValue.Value = false
--
elseif not v:IsA("Tool") then
--
print("Player does NOT have Item")
ShowYouDontHaveEvent:FireClient(player)
wait(3)
HideYouDontHaveEvent:FireClient(player)
--
end
end
else
--
end
end)
This is what I have right now, but the if player.Character then statement wont check if the player has a tool or not, and If the player has it in their backpack it wont check that either.
you shouldn’t use elseif for the backpack, a new if will work better. The tool should be a child of the player if equipped, if not equipped it will be in their backpack.