How do I make a script that checks if a tool is a child of a part then executes something and if not the executes something
1 Like
I think you will first have to define with a variable then use an if statement.
Something like,
if (variable) then
local toolfolder = game.ReplicatedStorage.save
local tool = script.Parent
tool.Equipped:Connect(function()
if toolfolder:WaitForChild("Wooden Sword") then
print("Already there")
else
local toolclone = tool:Clone()
toolclone.Parent = toolfolder
print("cloned")
end
end)
I’m pretty new to scripting but this did not work and I’m pretty sure ik why
What are you trying to do?
…
1 Like
Yeah, please try explain in more detail.
Im trying to make a script in a tool that when it is equipped it clones the tool (which is the scripts parent) and if the tool is already cloned in the folder then it will print already cloned.
if toolfolder:WaitForChild("Wooden Sword") then
I have never seen this before
ill test it but…
if toolfolder:FindFirstChild("Wooden Sword") then
Try this
ayo how did you write in code form?
-```lua
– print(‘Hello World’)
take out the “–”
I used backquotes (`) the key next to 1
local toolfolder = game:GetService("ReplicatedStorage").save
local tool = script.Parent
tool.Equipped:Connect(function()
if toolfolder:FindFirstChild(tool.Name) then
print("Has Tool")
else
local toolclone = tool:Clone()
toolclone.Parent = toolfolder
end
end)