Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script that detects a item in your inventory and gives you a item if it finds you have it help?

Asked by
608b 4
4 years ago
Edited 4 years ago
local tools = {"Demisting Blast", "Obscurring Clouds", "Rising Scorching Sun", "Sixfold", "Thunder Clap And Flash", "Unknowing Fire"}
local WaterWheel = game.ReplicatedStorage.Tools["Water Wheel"]

local function checkTool(player)
local backpack = player.Backpack
for i,v in pairs(backpack:GetChildren()) do
   if table.find(tools,1,v.Name) then return end
    WaterWheel:Clone().Parent = backpack
    end
end

script.Parent.MouseClick:Connect(function()
checkTool()
end)

I want to make it detect a certain item and give you a different item but I dont know how to make it work.

2 answers

Log in to vote
0
Answered by
Tokyo7979 131
4 years ago
Edited 4 years ago
local tools = {"Demisting Blast", "Obscurring Clouds", "Rising Scorching Sun", "Sixfold", "Thunder Clap And Flash", "Unknowing Fire"}
local WaterWheel = game.ReplicatedStorage.Tools["Water Wheel"]

local function checkTool(player)
local backpack = player.Backpack
for i,v in pairs(backpack:GetChildren()) do
   if table.find(tools,i,v.Name) then return end
    local newtool = WaterWheel:Clone()
    newtool.Parent = backpack
end

script.Parent.MouseClick:Connect(function()
checkTool()
end)

Hopefully this should work.

Ad
Log in to vote
0
Answered by
JPT79 92
4 years ago
local twool = game.ReplicatedStorage.SecondTool:Clone()
local tool = player.Backpack:FindFirstChild("FirstTool") --You must use findFirstChild here otherwise it can error if it can't find it

if tool then --If the tool exists
    twool.Parent = player.Backpack --Place the clone in the Backpack
    tool:Destroy --Destroy the old tool
end

I'm not the best at scripting, but I assume this should work

Answer this question