So, I want to only allow the player to exchange their tool for another one if they already have it in their inventory. I made a simple script which works, but you can just make the tool appear out of no where without having the thing you need to craft it. I don't know if i'm just being stupid because it sounds so simple but im new to programming and having difficulty.
script.Parent.Triggered:Connect(function(player) local Pack = player.Backpack local rs = game:GetService("ReplicatedStorage") local Item = rs:WaitForChild("Copper") local ItemClone = Item:Clone() ItemClone.Parent = Pack local RemoveItem = "Malachite Chunk" if player.Character and player.Character:FindFirstChild(RemoveItem) and player.Character[RemoveItem]:IsA("Tool") then player.Character[RemoveItem]:Destroy() end end)
This script is inside a proximity prompt, and maybe there is a way for the proximity prompt to just not show up if they don't have it in their inventory i'm thinking?
You would check the player's backpack instead of the player's character.
player.Character:FindFirstChild(RemoveItem) --instead of this player.Backpack:FindFirstChild(RemoveItem) --you would do this
Let me know if this helps
Since you want to disable the prompt if they don't have the item in their inventory, I made this localscript.
local player = game:GetService("Players").LocalPlayer local char = player.Character local prompt = game.Workspace.test.Attachment.ProximityPrompt --change this to your proximity prompt while wait(0.1) do if player.Backpack:FindFirstChild("Flash Light") or player.Character:FindFirstChild("Flash Light") then -- checking the player's backpack incase they dont have it equipped, and the character incase they do prompt.Enabled = true --enabling the prompt if they have the item else prompt.Enabled = false -- disabling if they dont end end
Change the flash light to the item you want, the localscript goes in starterplayerscripts. Hope this helps!