Hi. I want “if player.Backpack:FindFirstChild(“Paper”) == nil then” line to work more than once.
The line works perfectly when it’s executed the first time, because the backpack doesn’t contain “Paper”. However, the second time, after using :Destroy() (and yes it does work correctly in-game), it simply sees the line as false, which I don’t understand why. It’s like “Paper” is still there but invisible. Maybe I should do something other than :Destroy()? Or is it something completely different. Here is all my code:
local tool=nil
local ScreenGui=script.Parent.ScreenGui
local Frame=ScreenGui.Frame
local TextBox=Frame.Text
local Submit=Frame.btn_Submit
local bool=true
local PaperEvent=game:GetService("ReplicatedStorage").PaperEvent
local gui=script.Parent.ScreenGui
local function onPlayerClicked(hit)
local player = hit
if not player then
return
end
if player.Backpack:FindFirstChild("Paper") == nil then --The problematic line
tool = Instance.new("Tool")
tool.Name = "Paper"
tool.ToolTip = "You can write here."
tool.Parent = player.Backpack
local handle = Instance.new("Part", tool)
handle.Name = "Handle"
handle.Material = "SmoothPlastic"
handle.Size = Vector3.new(2, 0.05, 3)
handle.BrickColor = BrickColor.new(242, 243, 243)
tool.Equipped:Connect(function()
if bool then
ScreenGui:Clone().Parent = player.PlayerGui
bool = false
end
end)
PaperEvent:FireClient(player)
end
end
script.Parent.ClickDetector.MouseClick:Connect(onPlayerClicked)
:Destroy() script:
local PaperEvent=game:GetService("ReplicatedStorage").PaperEvent
PaperEvent.OnClientEvent:Connect(function()
local player = game:GetService("Players").LocalPlayer
local backpack=player:FindFirstChild("Backpack")
local tool=backpack:FindFirstChild("Paper")
local part = game:GetService("Workspace").Wall
part.ClickDetector.MouseClick:Connect(function()
tool.Handle.CFrame = part.CFrame
tool.Handle.Parent = part
tool:Destroy()
end)
end)
Last script:
local Players=game:GetService("Players")
local player=Players.LocalPlayer
local Frame=script.Parent
local Submit=Frame.btn_Submit
local tool=player.Character:FindFirstChildOfClass("Tool")
Submit.MouseButton1Click:Connect(function()
Frame.Visible=false
player.Character.Humanoid:UnequipTools()
tool.Equipped:Connect(function()
Frame.Visible=true
end)
end)